Destructor

If a class can have a constructor to set things up, it should also have a destructor to destruct the object.A destructor is also a member function like constructor whose name is the same as the class name and can be defined like any other member function.Tilde('~') symbol is used for destruct the object. A destructor takes no arguments, no return types. A destuctor cleanup the storage(memory area of the object). The symbol('~')refers to a NOT means destructor is a Not Constructor.A constructor initializes an object and a destructor deinitializes an object.


Example.....
#include<iostream.h>
#include<conio.h>
class abc
{
public:
abc()       //constructor without argument
{
cout<<"constructor";
}
~abc()   //destructor
{
cout<<"destructor";
}};
main()
{
clrscr();
abc ob1;
getch();
}

destructor

Explaination...
In above example we create an object ob1 of a class abc. Each class has only one destructor means destructor function cannot be overloaded .