Learning the lvalue and rvalue. The definition is whatever that can be \"address of\" is the left value and otherwise, it is rvalue.
I checked the operator precedenc
Based on my comment you can see why the compiler is against this kind of operation. The problem lies in general implementation of postfix operator ++
, which copies the object (int
in this case), increments the original one and returns that preincremented copy. You can think of it like of a function that is defined in following way:
int foo_operator(int& a)
{
int copy = a;
a += 1;
return copy;
}
If you try to use that function in your example, your compiler will also protest against it. The return value of that function is an rvalue.
You might now ask - what's up with the prefix operator ++
? Isn't that also a function that returns a value? And the answer would be - no. Prefix operator ++
returns a reference, not a copied value, thus the 'outcome' of it can be used with operand &
.