首页 文章

在Chrome V8 Engine Source中,它意味着什么?

提问于
浏览
-1

我在下面的代码中有一个问题 .

#define V8_DECLARE_ONCE(NAME) ::v8::base::OnceType NAME

在cpp文件中,'::'表示引用命名空间,但包含':: v8'的地方?

std::cout << ... << std::endl;

cout在'std'命名空间下,但是,在这种情况下,我不知道如何解释它 .

此代码的一部分是遵循一个 .

namespace v8 {
 namespace base {

 typedef AtomicWord OnceType;

 #define V8_ONCE_INIT 0

 #define V8_DECLARE_ONCE(NAME) ::v8::base::OnceType NAME

1 回答

  • 1

    ::ns 表示查找 ns 的根命名空间 . 它's to avoid possible namespace collisions, since it avoids looking in the current namespace, if you define your own namespace and it has the same name. Here'是一个证明差异的例子 .

    #include <iostream>
    
    namespace v8 {
    
    constexpr int val = 5;
    
    } // namespace v8
    
    namespace my {
    namespace v8 {
    
    constexpr int val = 10;
    
    } // namespace my::v8
    
    void some_func()
    {
      std::cout << ::v8::val << ", " << v8::val << '\n';
    }
    
    } // namespace my
    
    int main()
    {
      my::some_func();
    }
    

    打印 5, 10 .

相关问题