This code helps to understand the concept of destructors i.e to destroy an object using C++
Destructors helps to destroy an object which was created by a constructor.
#include using namespace std; int count=0; class destroy { public: destroy() { count++; cout<<"\n Number of object created="<<count; } ~destroy() { cout<<"\n number of object destroyed="<<count; count--; } }; int main() { cout<<"\n we have entered main function\n"; destroy A1, A2, A3; { cout<<"\n WE have entered the inner block\n"; destroy A4,A5; cout<<"\n we are exiting the ineer block\n"; } cout<<"\n we have returned to main \n"; cout<<"\n we are exiting main \n"; return 0; }
Submitted by Pratyasha Sahu (pratyashasahu)
Download packets of source code on Coders Packet
Comments