0

可以使用 :: 运算符在函数内访问全局范围的变量。由于全局范围没有名称,因此 :: 的左侧可能为空。我将如何访问在函数范围中定义的变量,该变量稍后在函数本身的块中被覆盖。在下面的代码中,我将如何访问初始化为 1 的变量?

extern int reused = 0;
int main()
{
    int reused = 1;
    {
        int reused = 2;
        cout << reused << endl; // how to get the reused inited to 1 here?
    }
}
4

1 回答 1

3

reused可以main使用::reused. 但是,没有办法在声明reused第三个的块内使用第二个reused。该语言没有为此提供机制。

于 2018-02-16T07:13:36.717 回答