For some reason I didn't manage to find this exact question. Why is it allowed to bind an rvalue
to const lvalue reference
, although it is impossible to to the same without the const
?
I do understand that the lifetime of the rvalue gets an extension somehow (in the first case) , but if so, why would the compiler disallow changing that 'rvalue', which is not really a temporary object anymore.
For example, consider the following code:
int main(){
int &i=3; //produces error
const int&j =3; //compiles
return 1;
}