Program For Copy Constructor
"Nice one Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class point {
public: int x,y;
point() {x=0,y=0; }
point(point &p)
{ x=p.x;
y=p.y;
}
};
void main()
{clrscr();
point p1,p2;
p1.x=10;
p1.y=20;
p2=p1; //copy constructor called here
cout<<"p2.x="<<p2.x<<endl;
cout<<"p2.y="<<p2.y;
getch();
}
"Nice one Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class point {
public: int x,y;
point() {x=0,y=0; }
point(point &p)
{ x=p.x;
y=p.y;
}
};
void main()
{clrscr();
point p1,p2;
p1.x=10;
p1.y=20;
p2=p1; //copy constructor called here
cout<<"p2.x="<<p2.x<<endl;
cout<<"p2.y="<<p2.y;
getch();
}
No comments:
Post a Comment