Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

:: scope resolution operator in front of a template function call in c++

I'm stuck with templates and scope resolution operator. I found these line in a file, I'm not able to figure out why we are using :: in front of a template function call, as of my knowledge we can only use :: in front of variables when refering to a global variable. Any Idea will be helpful

#define CREATE_AND_DECODE_TYPE(Type, buffer, pType) \
    ::CreateAndDecodeType<Type>(buffer, pType, throwVarBindExceptions, static_cast<Type *>(NULL))
like image 345
Vikram Singh Avatar asked Jan 20 '12 06:01

Vikram Singh


People also ask

What is a scope resolution operator :: used for?

The scope resolution operator :: is used to identify and disambiguate identifiers used in different scopes. For more information about scope, see Scope.

What is the :: in CPP?

Scope resolution operator :: (C++ only) The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class.

What is scope resolution in C?

The scope resolution operator is used to reference the global variable or member function that is out of scope. Therefore, we use the scope resolution operator to access the hidden variable or function of a program.

What is scope resolution operator in C with example?

The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class and used to access the static variables of class.


1 Answers

The scope resolution operator :: (at the beginning) forces the compiler to find the identifier from the global scope, without it the identifier is found relative to the current scope.

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)
}
like image 112
Martin York Avatar answered Sep 29 '22 18:09

Martin York