What is the :: before the class name?

Asked 2 years ago, Updated 2 years ago, 61 views

::Configuration * tmpCo = m_configurationDB;//pointer to current db I saw this chord I don't know what the hell :: is doing.

If you clear ::: declaration of tmpCo as a pointer to an object of the class Configuration Something like this pops up.

c++ syntax

2022-09-21 21:36

1 Answers

If you want to write only global namespace instead of namespace in your current location, put :: at the beginning.

For example, if you have different Configuration classes, then

class Configuration; // class 1 in the global namespace 
namespace MyApp
{
    class configuration; // class 1 and class 2 in different namespaces
    function blah()
    {
        Configuration::doStuff(...) // MyApp::Configuration, class 2
        ::Configuration::doStuff(...) // top-level Configuration, class 1
    }
}

Like this, when you're using the same name in another namespace namespace is used to limit


2022-09-21 21:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.