Wednesday 22 February 2012

Can we declare a base-class destructor as virtual? | Constructor in C++

Yes, we can declare a base-class destructor as virtual that makes all derived-class destructors as virtual even if they do not have the same name as base-destructor. The problem arises when the derived class's pointer refers to a base class.
For this reason, the base class destructor should be declared as virtual so that the appropriate destructor is called on calling the delete method of the base class object.