However, I am not entirely sure whether or not the actual problem lies in the struct or in the overloading part. Actually, I am completely clueless.

Any help appreciated!

Reedbeta
—
2009-01-11T00:45:07Z —
#2

There are two problems here.

First, the operator +=, and all assignment operators, have to return a reference to the object that was assigned to. This is because in C++ you can chain assignments, like a = b = c, which is parsed as a = (b = c), with 'a' getting the result of the assignment 'b = c'. Similarly you can do a = b += c, etc.

Second, you are using a non-const reference for the 'b' parameter to the operator, which means the argument has to be an l-value (for instance a variable). It does not work to pass an expression like '(a + a)' to this operator, since the result of '(a + a)' is a temporary Vector that is not an l-value. Making the parameter a const reference, however, allows you to use temporary objects freely.