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))
The scope resolution operator :: is used to identify and disambiguate identifiers used in different scopes. For more information about scope, see Scope.
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.
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.
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.
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With