#include"stdafx.h"
#include <iostream>
using namespace std;
//此处返回局部变量引用
void test(const int& b)
{
// b=1000;//常量引用能够防止修改b的值
cout<<"b="<<b<<endl;
}
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
int a=10;
//int&rel=10;//引用需要一块合法内存空间,故此处错误
const int& rel=100;//常量引用,此处相当于 int temp=10;int& rel=temp;
test(a);
system("pause");
return 0;
}
C++(常量引用)
最新推荐文章于 2024-07-14 13:39:50 发布