summaryrefslogtreecommitdiffhomepage
path: root/c++.html.markdown
diff options
context:
space:
mode:
authorcodesoap <codesoap@mailbox.org>2019-06-30 12:40:47 +0200
committercodesoap <codesoap@mailbox.org>2019-06-30 12:40:47 +0200
commit696cbc66bed9971d3152cd9fd24e268caf3aec99 (patch)
treed40a298db452e62b6a946399bb548ac8a7f60231 /c++.html.markdown
parent84cb0e88995b6d2f04a119cc25a695a33e1cbf9f (diff)
c++: Add more explanation to the += overloading example
Diffstat (limited to 'c++.html.markdown')
-rw-r--r--c++.html.markdown4
1 files changed, 4 insertions, 0 deletions
diff --git a/c++.html.markdown b/c++.html.markdown
index 80ad3a6c..fc9f6ce2 100644
--- a/c++.html.markdown
+++ b/c++.html.markdown
@@ -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;
}