开发者

The namespace starts with :: in C++ [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

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

This gtest has the example code.

::testing::Ass开发者_运维百科ertionResult IsEven(int n) {
  if ((n % 2) == 0)
    return ::testing::AssertionSuccess();
  else
    return ::testing::AssertionFailure() << n << " is odd";
}

How does it work? If the namespace is testing, isn't it testing::AssertionResult is the right usage?


The :: prefix refers to the global namespace, so this is like an absolute versus relative path specification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜