Should Destructor Be Virtual?
If Your Base Class Destructor Is Virtual Then Objects Will Be Destructed in a Order(Firstly Derived Object Then Base ). If Your Base Class Destructor Is Not...
If your base class destructor is virtual then objects will be destructed in a order(firstly derived object then base ). If your base class destructor is NOT virtual then only base class object will get deleted(because pointer is of base class "Base *myObj"). ... Therefore destructor should be pure virtual.
Should all destructors be virtual?
Any class that is inherited publicly, polymorphic or not, should have a virtual destructor. To put another way, if it can be pointed to by a base class pointer, its base class should have a virtual destructor. If virtual, the derived class destructor gets called and then the base class destructor.
Why should you declare a destructor as virtual?
Virtual destructors in C++ are used to avoid memory leaks especially when your class contains unmanaged code, i.e., contains pointers or object handles to files, databases or other external objects. A destructor can be virtual.