Question:

Is it possible to overload a destructor ? Give reason.

Show Hint

Constructors can be overloaded because objects can be created in different ways (with no initial data, with some data, etc.). Destructors cannot be overloaded because an object is always destroyed in the same way.
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

No, it is not possible to overload a destructor in C++. Reason: Function overloading requires that the functions have the same name but different signatures (i.e., a different number or type of parameters). A destructor, by definition, can never take any arguments. Its syntax is fixed as `~ClassName()`. Since it has no parameters, there is no way to create another destructor with a different signature. Therefore, a class can only have one destructor.
Was this answer helpful?
0
0