Write a program using copy constructor to copy data of an object to another object.
#include <iostream>
using namespace std;
class A
{
int x;
int y;
int z;
public:
A()
{
}
void input(int a,int b,int c)
{
x=a;
y=b;
z=c;
}
void display()
{
cout << "x is : " <<x<<endl;
cout << "y is : " <<y<<endl;
cout << "z is : " <<z<<endl;
}
};
int main()
{
A a1;
a1.input(10,20,30);
A a2 = a1;
a2.display();
return 0;
}
Comments
Leave a comment