问题
int&& rv = 10;
int& lv = rv; //no error
How is this possible?
Is this related to "reference collapsing rule"?
回答1:
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.
来源:https://stackoverflow.com/questions/37894068/assigning-rvalue-reference-to-lvalue-reference