小编Jap*_*pun的帖子

当"全局","本地"和"非常本地"变量存在同名时,如何访问"本地"变量

int i = 1;
int main()
{
    int i = 2;
    {
        int i = 3;
        cout << ::i << endl;  //i want to print 2, neither 1 nor 3
    }
    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我想打印2.默认情况下,cout << i << endl; print 3和cout << :: i << endl; 打印1.

c++ scope

3
推荐指数
1
解决办法
95
查看次数

标签 统计

c++ ×1

scope ×1