采纳
#include <iostream>
using namespace std;
class CPt
{
public:
double x;
double y;
void copy(CPt * pt)
{
if (pt != this) //不是给自己赋值
{ x = pt->x; y = pt->y; }
}
};
int main()
{
CPt a1, a2;
a2.x = 1.2;
a2.y = 2.3;
a1.copy(&a2);
cout << a1.x << " " << a1.y << endl;
}
判断a2的地址是否等于this 如果相等就是给自己赋值