#include<iostream>
using namespace std;
//函数的引用可以用作左值存在
int& test()
{
static int a = 10;
return a;
}
int main()
{
int& b = test();
cout << b << endl;
test() = 1000;//左值
cout << b << endl;
}
函数的引用可以用作左值存在
最新推荐文章于 2025-12-21 21:47:42 发布
本文探讨了如何在C++中使用函数引用作为左值,并通过`test()`函数的静态变量实例说明。在main函数中,修改`test()`的左值会影响全局变量,展示了C++中左值引用的特性。
1232

被折叠的 条评论
为什么被折叠?



