Calling base destructors
This is easy. We don't need to. We just need to make sure all destructors are virtual. Then they will automatically be called in reverse order.
So what is the order? Assume the following classes (with all virtual destructors:
class Base { .. } ; class SubClass : public Base { ... }; class SubSubClass : public SubClass { ... };
Now when we call
Base *b = new SubSubClass();
It will execute:
The constructor of Base
The constructor of SubClass
The constructor of SubSubClass
And when we clean up:
delete b;
The destructor of SubSubClass
The destructor of SubClass
The destructor of Base
The point here is: Always make destructors "virtual" and you have no problem.