int&& rv = 10;
int& lv = rv; //no error
How is this possible?
Is this related to "reference collapsing rule"?
int&& rv = 10;
int& lv = rv; //no error
First of all, a named object is never an rvalue. Second, since rv
is named object, it is not a rvalue, even though it binds to rvalue. Since rv
is lvalue, it can bind to lvalue without any problem.
Note that rvalue-ness is a property of an expression, not a variable. In the above example, an rvalue is created out of 10
and binds to rv
, which as I said, is lvalue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With