开发者

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

开发者 https://www.devze.com 2023-02-03 14:14 出处:网络
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 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

精彩评论

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

关注公众号