[K42-discussion] virtual destructors

Michal Ostrowski mostrows at watson.ibm.com
Fri Jul 7 09:53:36 EST 2006



On Thu, 2006-07-06 at 14:15 -0600, Donour Sizemore wrote:
> C++ requires that classes with virtual methods define a virtual 
> destructor. Older versions of gcc allow you to get away without it, but 
> gcc4 enforces it. I'm having trouble adding a destructor to the 
> VAllocServices class. I want to declare a destructor like this:
> 
> VAllocServices{
> 
> public:
> 
>   ...
> 
>   ~VAllocServices() = 0;
> 
> }
> 

This has the effect of saying no destructor.  I don't think you can do
this.

In K42, your destructors need to be virtual.  And they must exist - your
declaration says that the destructor is not implemented.

You should have instead:

VAllocServices {
public:
	virtual ~VallocServices() {};
}

In other words, my experience has always been that you can't use pur
virtual destructors and that your base classes must define them, even if
they have trivial implmentations.




> I've read several places that even with a pure virtual destructor, you 
> need to define a body for it. Such as:
> 
> VAllocServices::~VAllocServices() {}
> 

I don't think this is compatible with the "=0" syntax you were trying
earlier.

-- 
Michal Ostrowski <mostrows at watson.ibm.com>




More information about the K42-discussion mailing list