Write a program to use destructor


/* Write a program to use destructor*/

#include<iostream.h>

#include<conio.h>

class counter

{

int id;

public:

counter(int i)

{

id=i;

cout<<“\n destructor of object with id=”<<id<<“runs”;

}

~counter()

{

cout<<“\n object with id=”<<id<<“destroyed”;

}};

void main()

{

clrscr();

counter c1(1);

counter c2(2);

counter c3(3);

cout<<“\n end of main”;

getch();

}

/*output:

destructor of object with id=1runs

destructor of object with id=2runs

destructor of object with id=3runs

end of main

*/

Related Posts

Comments are closed.