114. Operator Overloading-II

Question.5

A developer implements both + and +=:

class Vec {
   int x;
public:
   Vec(int v) : x(v) {}
   Vec& operator+=(const Vec& o) { x += o.x; return *this; }
   Vec operator+(const Vec& o) const { Vec t = *this; t += o; return t; }
};

Why is + implemented in terms of +=?

Need Help? Refer to the Quick Guide below

Select Answer