Destructors
Let's understand the functionality of destructors.
We'll cover the following...
As the name suggests, a destructor is the opposite of a constructor.
The purpose of a destructor is to destroy a class object after it goes out of scope. This frees up the memory previously occupied by the object.
Properties #
-
Unlike the constructor, a destructor is called automatically.
-
We can define a destructor inside or outside the class. In its body, special actions, such as freeing up memory or releasing locks, can be performed.
-
A destructor can be declared by the
~
operator followed by the name of the class:~Account()
-
It does not have a return type or any parameters.
-
A class’s destructor cannot be overloaded.
-
Apart from ...