小编sha*_*p02的帖子

匿名命名空间歧义

请考虑以下代码段:

void Foo() // 1
{
}

namespace
{
  void Foo() // 2
  {
  }
}

int main()
{
  Foo(); // Ambiguous.
  ::Foo(); // Calls the Foo in the global namespace (Foo #1).

  // I'm trying to call the `Foo` that's defined in the anonymous namespace (Foo #2).
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如何引用匿名命名空间内的内容?

c++ namespaces anonymous ambiguity

18
推荐指数
2
解决办法
4704
查看次数

标签 统计

ambiguity ×1

anonymous ×1

c++ ×1

namespaces ×1