I'm just teaching myself C++ namespaces (coming from a C# background) and I'm really starting to think that even with all the things that C++ does better than most other languages, nested namespaces isn't one of them!
Am I right in thinking that in order to declare some nested namespaces I have to do the following:
namespace tier1
{
namespace tier2
{
namespace tier3
{
/* then start your normal code nesting */
}
}
}
As opposed to:
namespace tier1::tier2::tier3
{
}
à la C#?
This becomes even more demented when I need to forward declare:
namespace tier1
{
namespace tier2
{
namespace forward_declared_namespace
{
myType myVar; // forward declare
}
namespace tier3
{
/* then start your normal code nesting */
class myClass
{
forward_declared_namespace::myType myMember;
}
}
}
}
Bearing in mind that a typical system that I develop consists of:
MyCompany::MySolution::MyProject::System::[PossibleSections]::Type
Is this why you don't tend to see much use of namespaces in C++ examples? Or usually only single (not nested) namespaces?
UPDATE
For anyone interested, this is how I ended up tackling this issue.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…