That is a wrong fix. Yes, this is a pointer. But now, how would you go about doing copying without pointers?
Rather, write your copy assignment operator along these lines:
Code:
Point& Point::operator=(const Point& pt) {
x = pt.x;
y = pt.y;
return *this;
}
You may also include a check for self-assignment:
Code:
Point& Point::operator=(const Point& pt) {
if (this != &pt) {
x = pt.x;
y = pt.y;
}
return *this;
}
If you provide a swap member function, you could even write:
Code:
Point& Point::operator=(const Point& pt) {
Point temp(pt);
swap(temp);
return *this;
}
I am New to C++ Previously I used Code like this
var = new class_name(args)
var->member_function()->member_var
So I need to use new to adjust.
Then where's your delete? I suggest that you learn how to use C++ without pointers first. It seems to be causing you lots of unnecessary problems.