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?
Asked
Active
Viewed 730 times
-2
-
Look at this SO question: http://stackoverflow.com/questions/3199139/nested-namespaces-in-c – Icemanind Jan 15 '15 at 23:51
-
@icemanind No, the OP asks solely for nesting namespaces, not how to place objects into them (though I've been answering that also). – πάντα ῥεῖ Jan 16 '15 at 00:18
1 Answers
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
-
1I'll up-vote this as soon as I stop being as lazy as the OP ;) – Captain Obvlious Jan 15 '15 at 23:54
-
@DracoM. Well, looking at things like `std::chrono` it should become obvious. – πάντα ῥεῖ Jan 16 '15 at 00:08
-
@CaptainObvlious Well, with raising rep, I have the feeling to get lazier, which questions to answer ;) ... – πάντα ῥεῖ Jan 16 '15 at 00:10
-