-2

Well the question is straightforward, can I declare a namespace inside of another namespace? If so, what is the correct term for this namespace, would it be called an 'inner namespace' or a 'nested namespace', or perhaps something different altogether?

1 Answers1

3

"can I declare a namespace inside of another namespace?"

Yes, you can nest namespaces as much as you want

namespace A {
    struct thingA;
    void funcA();
    namespace B {
        struct thingC;
        void funcB();
        namespace C {
            struct thingC;
            void funcC();
        }
    }
}

And refer to the above declarations using the :: (scope) operator:

A::thingA thingA;
A::funcA();

A::B::thingB thingB;
A::B::funcB();

A::B::C::thingC thingC;
A::B::C::funcC();

"what is the correct term for this namespace, would it be called an 'inner namespace' or a 'nested namespace', or perhaps something different altogether?"

And also yes, it's usually called a 'nested namespace'.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190