I have read this and this, but I still do not understand why the following code compiles in XCode:
void func2(string &s) {
s = "yyyyy";
}
void func(string &&s) {
func2(s);
}
int main() {
func("xxxxx");
return 0;
}
I think an rvalue reference shouldn't be converted to a non-const lvalue reference, right? In general, what's the rule of conversion between lvalue references and rvalue references? I already know that const lvalue reference can bind to rvalues, but what about rvalue references (rather than rvalues)? Thanks a lot!
string &&ssis an lvalue which can bind to an lvalue reference. - nwpsis an rvalue reference. Why is it an lvalue? Is it because that it has identity and it is movable? If so, what is the difference between them? Thanks! - Yunsheng Bai