Copy Constructor in C++

(Copy Constructor)
#include <iostream>
#include <conio>
class point
{
private:
int x,y;
public:
point(int x1,int y1)
{
x=x1;
y=y1;
}
point(const point & p2)
{
x=p2.x;
y=p2.y;
}
int getx()
{
return x;
}
int gety()
{
return y;
}
};
int main()
{
point p1(50,100);
point p2=p1;
cout<<"the value of first obj for x and y is"<<endl;
cout<<p1.getx()<<endl;
cout<<p1.gety()<<endl;
cout<<"the value of second obj for x and y is"<<endl;
cout<<p2.getx()<<endl;
cout<<p2.gety()<<endl;
getch();
}

Output:-


Post a Comment

Total Pageviews