mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 23:33:00 +03:00
c++: Add more explanation to the += overloading example
This commit is contained in:
parent
84cb0e8899
commit
696cbc66be
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user