• Create Account

### #ActualCornstalks

Posted 05 April 2013 - 09:58 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.

Sorry, poor wording on my part. I meant non-const lvalue reference (i.e. the kind of reference we've been talking about in the code).

### #2Cornstalks

Posted 05 April 2013 - 09:57 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.

Sorry, poor wording on my part. I meant non-const lvalue reference (i.e. the kind of reference we've been talking about in the code). All the temporaries in that code are bound to constant lvalue references (though I'm not sure if any of them might be bound to rvalue references...).

### #1Cornstalks

Posted 05 April 2013 - 09:57 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.

Sorry, poor wording on my part. I meant non-const lvalue reference (i.e. the kind of reference we've been talking about in the code). All the temporaries in that code are bound to constant lvalue references.

PARTNERS