What is a Destructor?

Destructors are used to deallocate (free up) the memory space which is allocated to the constructors at the time of object creation. Destructors are declared with the same name as that of class name but a tilde (~) symbol is used along with it in order to differentiate between constructor and destructor. Destructor functions execute automatically when object of a class is destroyed. It does not have any return type and contains no argument that is why they cannot be overloaded.

E.g. of Destructor:
Class abc
{
public:
~abc ()
{
Cout<<”Object destroyed”; } };

More Questions

Leave a Reply

Word Verfication * Time limit is exhausted. Please reload CAPTCHA.