Can we overload destructor of a class in C++?

(Last Updated On: February 25, 2019)

Answer: No, destructor of a class in C++ cannot be overloaded. Only one empty destructor per class should be there. It must have a void parameter list. Destructor in C++ neither takes any parameters nor does it return anything.

So, multiple destructor with different signatures are not possible in a class. Hence, overloading is also not possible.

In below class, if we try to overload destructor for the class A, compiler will flash an error. For example, when we define destructor as ~A(int a) {} , compiler will throw error stating “ a destructor must have a void parameter list”.

 

 

NOTES:

1)Constructor overloading in C++ is possible.

 

 

2)Destructor in C++ cannot be overridden too. Don’t get confused with virtual destructor in C++.

If we try to override desturctor compiler will flash error, example below