← Operator Overloading

Compound Addition

hard

Add operator+=, operator+’s compound cousin: instead of producing a new Point2D, it modifies x and y in place and returns a reference to the same object it just changed.

Two details the lesson calls out as easy to get wrong: the return type is Point2D & (a reference to *this), not Point2D (a new copy) and not void – returning the wrong one compiles without complaint but breaks chaining and wastes a copy, so it’s worth writing return *this; as a fixed habit for every compound-assignment operator you write from here on.

Your solution

"Run" uses the sample stdin ("1 2 3 4"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution