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:

  1. The constructor of Base

  2. The constructor of SubClass

  3. The constructor of SubSubClass

And when we clean up:

delete b;
  1. The destructor of SubSubClass

  2. The destructor of SubClass

  3. The destructor of Base

The point here is: Always make destructors "virtual" and you have no problem.