Reputation: 21
Is there any expression that can be evaluated to give an lvalue? I believe expressions yield an rvalue which can be assigned to an lvalue.
Upvotes: 2
Views: 255
Reputation: 53496
Gabe is correct, but more specifically, any expression that results in a reference is an lvalue. But that's not all, pointer deferences and array access are both expressions that result in an lvalue.
Upvotes: 2
Reputation: 9130
Another example would be a function that returns a reference, i.e. std::vector
's index operator (reference operator[]( size_type n
) so you can do something like this:
std::vector< Z > vector;
vector[ y ] = z;
Upvotes: 1
Reputation: 86718
If you have x[y] = z;
, x[y]
is the lvalue and z
is the rvalue. Clearly x[y]
is an expression, and it can be evaluated. Therefore it can be evaluated to give an lvalue.
Upvotes: 7