What does it mean if namespace in C++ is qualified with ::? For example ::testing::Test.
It means that the testing namespace being referred to is the one off the global namespace, rather than another nested namespace named testing.
Consider the following corner case, and probably an example of bad design:
namespace foo
{
struct gizmo{int n_;};
namespace bar
{
namespace foo
{
float f_;
};
};
};
int main()
{
using namespace foo::bar;
::foo::gizmo g;
g.n_;
}
There are 2 namespaces named foo. One is the top-level hanging off of the "global" namespace, and another one is nested within foo::bar. then we go on to using namespace foo::bar, meaning any unqualified reference to gizmo will pick up the one in foo::bar::foo. If we actually want the one in foo then we can use an explicit qualification to do so:
::foo::gizmo