C++ 需要将::与memcopy一起使用

C++ 需要将::与memcopy一起使用,c++,scope,C++,Scope,我了解到“:”是一个范围解析操作符,我开始了解它的用法 但是,我看到“:”在某些代码中没有前缀。我以前从未见过这种情况。例如: ::memcopy(); ::GetKeyBoardState(); void GetKeyBoardState(); // a namespace foo { void GetKeyBoardState(); // b void bar() { ::GetKeyBoardState();

我了解到“:”是一个范围解析操作符,我开始了解它的用法

但是,我看到“:”在某些代码中没有前缀。我以前从未见过这种情况。例如:

::memcopy();
::GetKeyBoardState();
void GetKeyBoardState();           // a

namespace foo {
    void GetKeyBoardState();       // b

    void bar() {
        ::GetKeyBoardState();      // calls a
        GetKeyBoardState();        // calls b
        foo::GetKeyBoardState();   // calls b
        ::foo::GetKeyBoardState(); // calls b
    }
}

void bar() {
    ::GetKeyBoardState();          // calls a
    GetKeyBoardState();            // calls a
    foo::GetKeyBoardState();       // calls b
    ::foo::GetKeyBoardState();     // calls b
}

只是对语法和在代码中使用“:”的需要感到好奇。我删除了“:”,Intellisense没有红色下划线,所以我想知道发生了什么。谢谢

以::开头的限定名而不是作用域名是完全限定名。这意味着名称是绝对的,因此不执行相对名称查找

例如:

::memcopy();
::GetKeyBoardState();
void GetKeyBoardState();           // a

namespace foo {
    void GetKeyBoardState();       // b

    void bar() {
        ::GetKeyBoardState();      // calls a
        GetKeyBoardState();        // calls b
        foo::GetKeyBoardState();   // calls b
        ::foo::GetKeyBoardState(); // calls b
    }
}

void bar() {
    ::GetKeyBoardState();          // calls a
    GetKeyBoardState();            // calls a
    foo::GetKeyBoardState();       // calls b
    ::foo::GetKeyBoardState();     // calls b
}

这类似于绝对路径和相对路径在文件系统中的工作方式,以及完全限定域名与主机名的工作方式。

以::开头而不是范围名的限定名是完全限定名。这意味着名称是绝对的,因此不执行相对名称查找

例如:

::memcopy();
::GetKeyBoardState();
void GetKeyBoardState();           // a

namespace foo {
    void GetKeyBoardState();       // b

    void bar() {
        ::GetKeyBoardState();      // calls a
        GetKeyBoardState();        // calls b
        foo::GetKeyBoardState();   // calls b
        ::foo::GetKeyBoardState(); // calls b
    }
}

void bar() {
    ::GetKeyBoardState();          // calls a
    GetKeyBoardState();            // calls a
    foo::GetKeyBoardState();       // calls b
    ::foo::GetKeyBoardState();     // calls b
}

这类似于绝对路径和相对路径在文件系统中的工作方式,以及完全限定域名与主机名的工作方式。

我想,为了确保它不是从命名空间调用的。其他人可能会使用名称空间编写
可能具有同名函数,这可能会导致歧义。旁注:Intellisense将为您提供编译结果的粗略估计。实际上,编译通常会给出与Intellisense完全不同的结果。我想,为了确保它不是从名称空间调用的。其他人可能会使用名称空间编写
可能具有同名函数,这可能会导致歧义。旁注:Intellisense将为您提供编译结果的粗略估计。实际上,编译通常会给出与Intellisense完全不同的结果。