Is there a specific reason nested namespace declarations are not allowed in C++?

Billy ONeal picture Billy ONeal · Aug 30, 2010 · Viewed 8.7k times · Source

The standard does not allow code like this:

namespace Hello::World {

//Things that are in namespace Hello::World

}

and instead requires

namespace Hello { namespace World {

//Things that are in namespace Hello::World

}}

What is the rationale? Was this simply not thought of at the time, or is there a specific reason it is not included?

It seems that the first syntax more directly expresses in which namespace one is supposed to be, as the declaration mimics the actual use of the namespace in later code. It also results in less indentation if you are unfortunate enough to be using a "dumb" bracket counting indentation tool.

Answer

James McNellis picture James McNellis · Aug 30, 2010

The reason is most likely "because that's how the language evolved."

There has been at least one proposal ("Nested Namespace Definition Proposal" in 2003) to allow nested namespace definitions, but it was not selected for inclusion in C++0x.