考虑以下这段 C++ 代码片段:
namespace
{
void f()
{
}
class A
{
void f()
{
::f(); // VC++: error C2039: 'f' : is not a member of '`global namespace''
}
};
}
GCC编译这个代码没有问题。 而Visual C++ 2008却无法编译,会报C2039错误。这两个编译器哪一个是正确的?有没有办法正确地引用那个"全局"的f
?
编辑:Zack建议尝试,它可以在两个编译器中正常运行。对我来说看起来有点奇怪。
namespace
{
void f()
{
}
class A
{
void f();
};
}
void A::f()
{
::f();
}
class A
的定义之外的A::f
提取出来,会发生什么?如果您将其完全提取出匿名命名空间声明,又会发生什么? - zwol::A::f
可能会有问题。 - detunized