1

Suppose I have a pair of nested namespaces like these:

namespace A
{
   namespace B
   {
      int foo = 0;
   }
}

If B was a class, I could write using A::B to avoid typing A:: every time. I attempted to do the same thing with B as a namespace, but the compiler informed me that this was not allowed.

If I were to write using namespace A::B, this would introuduce everything contained in B into the local namespace. I could write using namespace A, which would produce the desired results (writing B::foo), but this would come with everything else in A.

Is it possible to bring B into the local namespace without everything else in A?

John Leuenhagen
  • 576
  • 7
  • 23

1 Answers1

2

You can do this with a different syntax, a namespace alias:

namespace B = A::B;
aschepler
  • 70,891
  • 9
  • 107
  • 161