繁体   English   中英

::范围解析运算符在c ++中的模板函数调用之前

[英]:: scope resolution operator in front of a template function call in 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)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM