lvalue
- can pass an lvalue
- the function has a copy of the passed object’s data
- Or can pass movable rvalue
- the function now owns the passed object’s data
Characteristic
- represent persistent objects
- occupies memory that can be accessed, either on stack or heap
- remain valid until going out of scope
Lvalue reference
int x;
int& y = x;
y = 3;- Typically implemented as as a pointer
- Require that x has a name and an address
- x must be an lvalue
- Cannot bind and lvalue reference to an rvalue
int&x = 3; // ERROR- …unless the reference is const
const int& x = 3 // OKTip
pass an lvalue, not rvalue
the function can modify the passed object’s data through the Rvalue reference
Const lvalue reference
Tip
can pass lvalue or rvalue
function canNOT modify the passed object’s data through the reference