I think there\'s something I\'m not quite understanding about rvalue references. Why does the following fail to compile (VS2012) with the error \'foo\' : cannot conver
It's the "no name rule". Inside bar
, x
has a name ... x
. So it's now an lvalue. Passing something to a function as an rvalue reference doesn't make it an rvalue inside the function.
If you don't see why it must be this way, ask yourself -- what is x
after foo
returns? (Remember, foo
is free to move x
.)