关于C++中拷贝构造函数
#include<iostream.h>class point
{
public:
point(int xx=0,int yy=0) {X=xx;Y=yy;}
point(point &p);
int getX() {return X;}
int getY() {return Y;}
private:
int X,Y;
};
point::point(point &p)
{
X=p.X;
Y=P.Y;
cout<<"拷贝函数被调用"<<endl;
}
void fun1(point p)
{cout<<p.getX()<<endl;}
point fun2()
{
point A(1,2);
return A;
}
void main()
{
point A(4,5);
point B(A);
cout<<B.getX()<<endl;
fun1(B);
B=fun2();
cout<<B.getX()<<endl;
}
为什么运行会出错呢 并且point::point(point &p)
{
X=p.X;
Y=P.Y;
cout<<"拷贝函数被调用"<<endl;
}
我也不太明白啊 请教高手给讲解下 谢谢啊