Create a class for counting the number of objects created and destroyed within the various block using constructor and destructors.




Implementation of the above problem:
#include<iostream.h>
int count=0;
class contdest
{
public:
contdest()
{
cout<<"\nObject Created ="<<count++;
}
~contdest()
{
cout<<"\nObject Destroyed = "<<--count;
}
};
void main()
{
cout<<"\nMain Block\n";
contdest a,b,c;
{
cout<<"\nBlock 1\n";
contdest d;
}
cout<<"\nAgain main Block\n";
contdest e;
}





Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: