• Create Account

### #ActualRyan_001

Posted 05 April 2013 - 09:02 AM

The thing is, you're not supposed to be able to take an l-value reference to an r-value. Yes, there are some ways that an r-value reference may be modified (through calling non-const member functions, or if you're using move semantics), but they're not supposed to be modified through any other means.

But it's possible Visual Studio allows it. I just know that in standard C++, it's illegal.

But you bind rvalues to lvalue references all the time.  For example:

string s("hello");
cout << s.find(string("l") + string("o")) << endl;


This may be a contrived example, but temporary values are constantly bound to lvalue references.

### #1Ryan_001

Posted 05 April 2013 - 09:01 AM

The thing is, you're not supposed to be able to take an l-value reference to an r-value. Yes, there are some ways that an r-value reference may be modified (through calling non-const member functions, or if you're using move semantics), but they're not supposed to be modified through any other means.

But it's possible Visual Studio allows it. I just know that in standard C++, it's illegal.

But you bind rvalues to lvalue references all the time.  For example:

string s("hello");
cout << s.find(string("l") + string("o")) << endl;

This may be a contrived example, but temporary values are constantly bound to lvalue references.

PARTNERS