reffunc.cpp
来自「本文件包包含了大量用VC++开发的应用程序界面」· C++ 代码 · 共 41 行
CPP
41 行
/*
reffunc.cpp. An example of using reference
functions as lvalues.
*/
#include <stdio.h>
#include <iostream.h>
int IntArray[] = {1, 2, 3};
#define SIZE (sizeof(IntArray)/sizeof(int))
int& RefFunc(int x);
int main ()
{
int x;
cout << "Before Reference Function: " << endl;
for (x = 0; x < SIZE; ++x)
{
cout << "IntArray[" << x << "] = ";
cout << IntArray[x] << endl;
}
for (x = 0; x < SIZE; ++x)
RefFunc(x) = x * 42;
cout << endl << "After Reference Function: " << endl;
for (x = 0; x < SIZE; ++x)
{
cout << "IntArray[" << x << "] = ";
cout << IntArray[x] << endl;
}
return (0);
}
//
// Return a reference to the array member indexed by
// parameter.
int& RefFunc (int x)
{
return (IntArray[x]);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?