As you may know, in C++ a destructor is generally used to deallocate memory and do some other cleanup for a class object and it’s class members whenever an object is destroyed. Destructors are distinguished by the tilde, the ‘~’ that appears in front of the destructor name. The need for virtual destructors is best illustrated by an example. Take a look at the code below: Example without a Virtual Destructor:#include iostream.hclass Base{ public: Base(){ cout<<"Constructing Base";} // this is a destructor: ~Base(){ cout<<"Destroying Base";}};class Derive: public Base{ public: Derive(){ cout<<"Constructing Derive";} ~Derive(){ cout<<"Destroying Derive";} };void main(){ Base *basePtr = new Derive(); delete basePtr;}The output of running the code above would be: Constructing Base Constructing Derive Destroying Base Based on the output above, we can see that the constructors get called in the appropriate order when we create the Derive class object pointer in the main function. But there is a major problem with the code above: the destructor for the "Derive" class does not get called at all when we delete ‘basePtr’. So, how can we fix this problem? Well, what we can do is make the base class destructor virtual, and that will ensure that the destructor for any class that derives from Base (in our case, its the "Derive" class) will be called.