[Insight-users] How to build a sub class of itk::XMLReaderBase...??

Mathieu Malaterre Mathieu . Malaterre at creatis . insa-lyon . fr
Fri, 19 Sep 2003 13:53:57 +0200


Sergio Andrés wrote:
> Hi everybody again!
> 
> I want to create a new class that inherits from itk::XMLReaderBase.
> 
> But, I have some problems with destructors: 
> 
>  1. I create a new instance of my class with "MyClass * pt = new MyClass();"
>  2. I use my class...
>  3. I try to delete the pointer pt with "delete pt".
> 
> But I get a run-time error. 
> I think it could be due to the way I defined MyClass, with public constructor 
> and destructor....
> 
> However, if I call to "pt->UnRegister();" instead of "delete pt", the program
> finishes correctly, provided that the destructor method in MyClass is empty.
> 
> 
> Could anyone help me with this problem...??
> Should I define MyClass with a style like ITK classes (SmartPointers, 
> static New methods ...) ???

Sergio,

	You have to forget everything you know about new/delete in C++, because 
ITK use Smart pointer instead. So you don't have to worry about memory 
management -well most of the time-.

	Please read the ItkSoftwareGuide.pdf: section 3.2.4 page 22 (or 48/565 
for pdf file).

HTH
mathieu