Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaces qualified with :: in C++

Tags:

c++

namespaces

What does it mean if namespace in C++ is qualified with ::? For example ::testing::Test.

like image 204
Leonid Avatar asked Aug 30 '10 20:08

Leonid


1 Answers

:: is the scope resolution operator. It always means "search the global namespace for the symbol on the right." For example:

namespace testing {
    int a = 1;
}

namespace foo {
    namespace testing {
        int a = 2;
    }

    int b = ::testing::a; // b has the value 1
    int c = testing::a; // c has the value 2
}
like image 88
Peter Ruderman Avatar answered Oct 15 '22 17:10

Peter Ruderman