Thursday, December 13, 2012

Write a program of Destructor in c++


#include<iostream.h>
#include<conio.h>
int count=0;
class Alpha
{
 public:
  Alpha()
  {
   count++;
   cout<<"\n number of object created"<<count;
  }
  ~Alpha()
  {
   cout<<"\n number of object destroyed"<<count;
   count--;
  }
 };
int main()
{
clrscr();
 cout<<"\n\nEnter main\n";
 Alpha A1,A2,A3,A4;
 {
  cout<<"\n\nEnter block1\n";
  Alpha A5;
 }
 {
  cout<<"\n\n Enter block2\n";
  Alpha A6;
 }
 cout<<"\n\n Re-enter main\n";

 return 0;
}

Output