C++ program to destruct the objects using constructors and destructors

0
730

C++ program to destruct the objects using constructors and destructors

CONSTRUCTION:

  • Start the program
  • Create the objects for constructors functions invocation
  • Call the constructor for the object creation and destructor to destroy the objects.
  • Stop the program.

PROGRAM:

#include<iostream.h>
 #include<conio.h>
 int c=0;
 class xyz
{
 Public:
 xyz()
 {
 c++;
 cout<<”\n no.of objects are created”<<c;
 }
 ~xyz()
{
cout<<”\n no.of objects are destroyed”<<c;
c--;
}
};
int main()
{
cout<<”\n Enter main”;
xyz x1,x2,x3,x4;
{
cout<<”\n Enter block1”;
xyz x5;
}
{ 
cout<<”\n Enter Block2”;
xyz x6;
 }
cout<<”\n Re-Enter Main”;
return 0;
}

 

Leave a Reply