Boost logo

Boost :

From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2008-05-03 16:14:04


Peter Dimov wrote:
> Stefan Seefeld:
>> How do you prevent then any users deriving from your classes, from
>> adding their own destructors ? Their destructors might not be invoked,
>> since the base destructor isn't virtual.
>
> How does this look in code?

#include <iostream>

struct Base
{
   ~Base() { std::cout << "~Base" << std::endl;}
};

struct Derived : Base
{
   ~Derived() { std::cout << "~Derived" << std::endl;}
};

void destruct(Base *b) { delete b;}

int main(int, char **)
{
   Derived *derived = new Derived;
   destruct(derived);
}

Run the above code as is, and with the base destructor made virtual, to
see the difference.

Regards,
                Stefan

-- 
       ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk