Confusion About C++ Global Namespace
c++, namespaces, scope
Solution
`using namespace Foo;` brings all the contents of `namespace Foo` into the context of the current namespace.
Since `namespace Bar` is among the contents of `namespace Foo` and the current namespace on the line with the `using` statement is the global namespace, `namespace Bar` is brought into the context of the global namespace.
Problem
From my understanding, appending `::` to the front of a namespace refers to the global namespace, regardless of any using statements or parent namespaces. If that is the case, and I haven't mis-understood anything, then why does such code compile (at least in Visual Studio): ``` namespace Foo { namespace Bar { class X; } } using namespace Foo; int main(void) { ::Bar::X x; } ```