源程序:
#include <iostream>
using namespace std;
int oneX = 10;
int oneY = 20;
int &refValue(int &x)
{
return x;
}
int main()
{
refValue(oneX) = 30;//返回值是引用,可以作为左值
cout << "oneX=" << oneX << endl;
refValue(oneY) = 40;//返回值是引用的函数调用表达式,可以作为左值使用
cout << "oneY=" << oneY << endl;
system("pause");
return 0;
}
运行结果: