创建引用变量的方法,类型&
比如 创建int类型的应用 int&
#pragma region firstref.8.2
//程序清单8.2
//firstref.cpp -- defining and using a reference
#if 0
#include <iostream>
int main()
{
using namespace std;
int rats = 101;
int& rodents = rats; //rodents is a reference
cout << "rats = " << rats;
cout << ",rodents = " << rodents << endl;
rodents++; //加的是引用指向地址内的数值
cout << "rats = " << rats;
cout << ",rodents = " << rodents << endl;
//some inplementations require type casting the following
//addresses to type unsigned
cout << "rats address = " << &rats;
cout << ",rodents address = " << &rodents << endl;
return 0;
}
#endif
#pragma endregion
这是一个简单的例子,旨在理解引用变量的创建