patterncppCritical
What is the meaning of prepended double colon "::"?
Viewed 0 times
doublecolonthemeaningprependedwhat
Problem
I found this line of a code in a class which I have to modify:
and I don't know what exactly means the double colon prepended to the class name. Without that I would read: declaration of
I also found:
::Configuration * tmpCo = m_configurationDB;//pointer to current dband I don't know what exactly means the double colon prepended to the class name. Without that I would read: declaration of
tmpCo as a pointer to an object of the class Configuration... but the prepended double colon confuses me.I also found:
typedef ::config::set ConfigSet;Solution
This ensures that resolution occurs from the global namespace, instead of starting at the namespace you're currently in. For instance, if you had two different classes called
Basically, it allows you to traverse up to the global namespace since your name might get clobbered by a new definition inside another namespace, in this case
Configuration as such:class Configuration; // class 1, in global namespace
namespace MyApp
{
class Configuration; // class 2, different from class 1
function blah()
{
// resolves to MyApp::Configuration, class 2
Configuration::doStuff(...)
// resolves to top-level Configuration, class 1
::Configuration::doStuff(...)
}
}Basically, it allows you to traverse up to the global namespace since your name might get clobbered by a new definition inside another namespace, in this case
MyApp.Code Snippets
class Configuration; // class 1, in global namespace
namespace MyApp
{
class Configuration; // class 2, different from class 1
function blah()
{
// resolves to MyApp::Configuration, class 2
Configuration::doStuff(...)
// resolves to top-level Configuration, class 1
::Configuration::doStuff(...)
}
}Context
Stack Overflow Q#4269034, score: 639
Revisions (0)
No revisions yet.