命名空间以:: C ++开头

时间:2011-01-12 04:11:13

标签: c++ namespaces

  

可能重复:
  What's the purpose of a leading “::” in a C++ method call

This gtest有示例代码。

::testing::AssertionResult IsEven(int n) {
  if ((n % 2) == 0)
    return ::testing::AssertionSuccess();
  else
    return ::testing::AssertionFailure() << n << " is odd";
}

它是如何工作的?如果命名空间正在测试,是不是测试:: AssertionResult是正确的用法?

1 个答案:

答案 0 :(得分:3)

::前缀是指全局命名空间,因此这就像绝对路径规范相对路径规范。