rvalue references are denoted by double &&'s, such as this:
1 2
int foo;
int&& refData = foo; // <- rvalue reference
Im very confused because isnt 5 a rvalue because it cannot be on the left side of the = sign because it does not have a memory location defined.
Yeah the naming is confusing. It's an lvalue reference... but it's const, which is why it can't appear on the left of the = operator.
Likewise, rvalue references can appear on the left side of the = operator.
Personally I think the naming convention is absurd and confusing. So don't worry if you find yourself still being confused. I'm even still confused why they're named the way they are. I also had to look this up to make sure I was telling you the right thing.
isnt 5 a rvalue because it cannot be on the left side of the = sign because it does not have a memory location defined.
The = sign is inconsequential, but you're right to pick on memory location: lvalue expressions identify objects that have memory locations, rvalue expressions identify objects that don't.
What you need to keep in mind, if you really want to understand this, is that lvalue and rvalue are categories of expressions, while lvalue reference and rvalue reference are types of variables.
5 is an expression whose value category is rvalue (since any non-string literal is rvalue).
refData is a variable whose type is lvalue reference (to const int). This has nothing to do with what 5 is. It's just the type you used in declaration.
Isnt it a rvalue reference....
An rvalue reference, as Disch correctly points out, is a variable with rvalue reference type, such as int&&.
An rvalue reference behaves just like an lvalue reference except that it can bind to a temporary (an rvalue), whereas you can not bind a (non const) lvalue reference to an rvalue.
what is the difference between rvalue references and lvalue references?
The main difference is when a function is overloaded such that one overload expects lvalue reference paramter, and another overload expects rvalue reference parameter, then when the function is called with lvalue argument, the first overload is selected, and when the function is called with rvalue argument, the second overload is selected.
Arent lvalue references a alias for only a object but 5 isnt a object.
5 isn't an object, but constint& refData = 5; creates an object of type int. You can take its address later if you'd like.
An rvalue reference behaves just like an lvalue reference except that it can bind to a temporary (an rvalue), whereas you can not bind a (non const) lvalue reference to an rvalue.