From 696cbc66bed9971d3152cd9fd24e268caf3aec99 Mon Sep 17 00:00:00 2001 From: codesoap Date: Sun, 30 Jun 2019 12:40:47 +0200 Subject: [PATCH] c++: Add more explanation to the += overloading example --- c++.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) 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; }