我有以下代码,我不知道如何访问此设置中的匿名命名空间内的x。请告诉我如何?访问匿名命名空间中的变量(C++)
#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;
}
你不能。不要这样做。 –
非常感谢... !!! –
一些相关的阅读:http://stackoverflow.com/questions/9622874/unnamed-namespace-access-rules – NathanOliver