basic

int a = 10; // a is lvalue, 10 is rvalue, have memory
int b = a + 10;// a + b is rvalue, temporary

lvalue reference

左值引用能做什么?

void test(int& a){}
 
int a = 10;
test(a); //Work!!!
test(10); //Error!!!

那怎样才能让左值引用接收右值呢?

void test(const int& a){}
test(10); //Work!!!

rvalue reference

void test(int && a){}
int b = 10;
test(10); //Work!!!
test(b); //Error!!!

右值引用意味着我们能分辨临时对象和左值了。譬如:

void test(int && a){std::cout << "rvalue " << a << std::endl;}
void test(const int & a){std::cout << "lvalue " << a << std::endl;}
test(10);
// rvalue 10