【发布时间】:2017-01-24 16:49:02
【问题描述】:
我有以下代码,但我不知道如何在此设置中访问匿名命名空间内的 x。请告诉我怎么做?
#include <iostream>
int x = 10;
namespace
{
int x = 20;
}
int main(int x, char* y[])
{
{
int x = 30; // most recently defined
std::cout << x << std::endl; // 30, local
std::cout << ::x << std::endl; // 10, global
// how can I access the x inside the anonymous namespace?
}
return 0;
}
【问题讨论】:
-
你不能。不要那样做。
-
@NathanOliver 非常感谢!
-
为什么cmets部分已经给出了答案?
标签: c++ static anonymous unnamed-namespace