Destructors
Following example shows the use of Destructor Function:
#include < iostream.h > class Test { public: Test(); ~Test(); }; Test :: Test()   //here is the definition of constructor { cout<<"Constructor of class Test called: << endl; } Test :: ~Test()   //here is the definition of destructor { cout<<"Destructor of class test called" << endl; } void main() { Test x;   //constructor is called while creating cout<<"terminating main()' << ; }   //object x goes out of scope, destructor is called |
OUTPUT:
Constructor of class Test called
Terminating main()
Destructor of class test called
CACKLE comment system