#include<iostream>
int a; //1st a
void f()
{
int a; //2nd a
{
int a; //3rd a
// ::a refers to the global a here
// simply a refers to the a inside this namespace
//What should i do to access and modify 2nd a here in this namespace
}
}
我知道要访问全局名称我需要使用::a 但是如果我想访问的名称在函数内部并且我在该函数定义的 namespace 内我该怎么办?
最佳答案
没有从内部范围访问第二个a
的语法。您必须事先创建一个唯一的别名,例如:
void f()
{
int a;
{
int& outer_a = a;
int a;
关于c++ - 我应该怎么做才能访问变量 'a'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46880947/