Monday, October 20, 2014

Write a program to use of copy constructor.

Prog 36: Write a program to use of copy constructor.
#include < iostream.h >
#include < conio.h >
class data
{
int x;
public:
data(int a)
{
x=a;
}
data()
{}
data(data &d)
{
x=d.x;
}
void display()
{
cout<<"\n x="<<x;
}
};
void main()
{
clrscr(); data A(10); data B; B=A;
data C(20); data D(C); A.display(); B.display(); C.display(); D.display();
getch();
}
Output:

x=10 x=10 x=20 x=20

No comments: