
3 May
2008
3 May
'08
8:14 p.m.
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...