class Point {
public:
Point(int x, int y) : { x = new int(x); y = new int(y) }
...
...
Point& operator=(const Point& other) {
if(this!=&other){
delete x;
delete y;
x = new int(*other.x);
y = new int(*other.y);
}
return *this;
}
private:
const int* x;
const int* y;
}
即使其中的 x 和 y 已经初始化,这个 operator= 的实现会起作用吗?删除 const 指针是否允许我们重新分配它?