::c++中模板函数调用前面的作用域解析运算符



我一直使用模板和范围解析运算符。我在一个文件中发现了这一行,我不明白为什么我们在模板函数调用前使用:,据我所知,当引用全局变量时,我们只能在变量前使用:。任何想法都将有助于

#define CREATE_AND_DECODE_TYPE(Type, buffer, pType) 
    ::CreateAndDecodeType<Type>(buffer, pType, throwVarBindExceptions, static_cast<Type *>(NULL))

作用域解析运算符::(在开头)强制编译器从全局作用域中查找标识符,如果没有它,则可以找到相对于当前作用域的标识符。

namespace X
{
    namespace std
    {
        template<typename T>
        class vector {};
    }
    std::vector<int>     x;       // This is X::std::vector
    ::std::vector<int>   y;       // This is the std::vector you normally expect (from the STL)
}

最新更新