You are passing a reference to your function - which means (as the error says) what you pass into the function needs to be something that can be used on the left hand side of an assignment (also known as an
lvalue
; the bit to the right of the assignment operator is an
rvalue
):
a = b;
a
must be an
lvalue
: a value that can be changed.
If you wrote this:
666 = b;
You would expect it to fail, because you cannot change teh value of a constant - it is not an
lvalue
!
Similarly, you can't write this:
foo() = b;
Because you have no idea what
foo
might return, but it's not going to be anything you can change!
The same requirement is there when you take a reference: because a reference is the object rather than the value of the object changing it can affect the outside world - so you can only ever take a reference of an
lvalue
for exactly eteh same reasons as above.
Make sense now?