C++ 右值引用定义
#include<iostream>
using namespace std;
int main()
{
//左值:
int a=10;
int b=9;
//右值:
/*
a+b,add(a,b),1000,'a',"123";
*/
//左值引用必须用左值初始化
int & ra = a;
int & rb = b;
//err: int & rd = a+b;
//const左值引用可以用右值初始化
const int & rc = 100;
//右值引用需要用右值初始化
int && rab = a+b;
rab = 900;
cout<<"rab="<<rab<<endl;
//err: int && re = a;
//err: const int && rf = a;
//err: int && rg = ra;
//右值引用本身是左值,所以不可以初始化其他右值引用
//err: int && rh = rab;
}