A distructor is a function ,which executes autometically,when an object is destroyed.It free the memory when the object of a class is destroyed.There asre some points to be remembered while using a destructor function
:
1. The name of destructor function should be the same as that of a class but should start with a "~" symbol.
2. It cannot be declared static.
3. A destructor function should be declared with no return.
4. It should be declared in public section in a class.
Class Class_name
{
private:
----------------- //declare private zone
-----------------
Public;
----------------//declare publice zone
----------------
class name(); // constructor function
~ class name (); // destructor function
------------
};
:
1. The name of destructor function should be the same as that of a class but should start with a "~" symbol.
2. It cannot be declared static.
3. A destructor function should be declared with no return.
4. It should be declared in public section in a class.
Class Class_name
{
private:
----------------- //declare private zone
-----------------
Public;
----------------//declare publice zone
----------------
class name(); // constructor function
~ class name (); // destructor function
------------
};
0 comments:
Post a Comment