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;
}
Will this implementation of operator= work even if x and y of this were already initialized? does deleting a const pointer allow us to reassign it?
That’s not a
constpointer, but a pointer toconst. So you can modify the pointer, you can’t that which it points to.A
constpointer isand your code wouldn’t compile then.