一 引用折叠规则
1、T& + & = T&
2、T& + && = T&3、T&& + & = T&
4、T或T&& + && = T&&
二 例子如下
#include "stdafx.h"
#include <iostream>
#include <typeinfo.h>
using namespace std;
typedef int & lRef;
typedef int && rRef;
typedef const int & lcRef;
typedef const int && rcRef;
void main()
{
int a = 10;
// 左值引用
lRef b = a; // b : int &
lRef &c = a; // c : int &, & and & = &
// 右值引用
rRef d = 10; // d : int&&
rRef&& e = 10; // e : int&&, && and && = &&
lRef&& f = a; // f : int&, & and && = &
rRef& g = a; // g : int&, && and & = &
//int a = 10;
左值引用
//lcRef b = a; // b : const int &
//lcRef &c = a; // c : const int &, const & and & = const &
右值引用
//rcRef d = 10; // d : const int&&
//rcRef&& e = 10; // e : const int&&, const && and && = &&
//lcRef&& f = a; // f : const int&, const & and && = &
//rcRef& g = a; // g : const int&, const && and & = &
}
三 模板函数参数
#include "stdafx.h"
#include <iostream>
#include <typeinfo.h>
using namespace std;
template<typename T>
void FunTemple(T && param)
{
}
void main()
{
// inParam : int T : int& param : int&
// inParam : int& T : int& param : int&
// inParam : int&&(无名) T : int param : int&&
// inParam : int&&(有名) T : int& param : int&
// inParam : const int T : const int& param : const int&
// inParam : const int& T : const int& param : const int&
// inParam : const int&& T : const int& param : const int&
int inParam = 10;
FunTemple(inParam);
}