Write a program to use copy constructor


 

/* Write a program to use  copy constructor*/

 

#include<iostream.h>

#include<conio.h>

class counter

{

private:

int count;

public:

counter(int x)

{

count=x;

}

counter(counter &ob)

{

count=ob.count;

}

void show()

{

cout<<“count=”<<count<<endl;

}};

void main()

{

clrscr();

counter c1(10);

counter c2(c1);

c1.show();

c2.show();

getch();

}

output:

count=10

count=10

Related Posts

Comments are closed.