c++: Add more explanation to the += overloading example

This commit is contained in:
codesoap 2019-06-30 12:40:47 +02:00
parent 84cb0e8899
commit 696cbc66be

View File

@ -553,10 +553,14 @@ Point Point::operator+(const Point& rhs) const
return Point(x + rhs.x, y + rhs.y);
}
// It's good practice to return a reference to the leftmost variable of
// an assignment. `(a += b) == c` will work this way.
Point& Point::operator+=(const Point& rhs)
{
x += rhs.x;
y += rhs.y;
// `this` is a pointer to the object, on which a method is called.
return *this;
}