Why do we need virtual destructor in c++
Anonimo
When we destroy objects of derived classes, the derived class's dtor is called first, then the base class's dtor. But the derived dtor may free/destroy members from the base class. This is a problem when the base class's dtor is called. Making the base class's dtor virtual, prevents the base class dtor from being called, assuming that the derived class has defined it's own dtor. General rule, is if you have a class inherit from another, make the base class virtual.