Simple Destructor Program in C++


#include<iostream.h>

#include<conio.h>

class cat

{

private:

int age,count;

public:

cat()

{

count ++;

cout<<"age is:"<<count;

}

~cat()

{

cout<<"object is destroyed"<<count;

count --;

}

};

int main()

{

clrscr();

cout<<"main block";

cat obj1;

{

cout<<"block";

cat obj2,ob3;

}

getch();

return 0;

}

To run:



Output:



No comments:

Post a Comment

theengineerschoice01@gmail.com