#include<iostream>
using namespace std;
//引用函数不能返回局部变量,否则使用一次后内存会删除
//引用可以变成左值用来使用
int& func()
{
static int a = 20;
return a;
}
void main()
{
int& ref = func();
cout << ref << endl;
func() = 100;
cout << ref << endl;
}
c++引用注意事项
最新推荐文章于 2023-12-09 16:08:19 发布