使用
#include <iostream>
using namespace std;
int a = 1;
int main()
{
int a = 2;
if(true)
{
int a = 3;
cout << a
<< " " << ::a // Can I access a = 2 here?
<< " " << ::a << endl;
}
cout << a << " " << ::a << endl;
}
拥有输出
3 1 1
2 1
有没有办法在等于3的那个'a'的if语句中访问等于2的'a',并输出结果?
3 2 1
2 1
注意:我知道这样做不应该(代码不应该到达需要我问的地步)。这个问题更多的是"能不能做到"。