Why is it forbidden to open multiple namespaces at a stretch?

前端 未结 2 2177
有刺的猬
有刺的猬 2021-02-13 01:39

It\'s possible to do using namespace foo::bar; (i.e., using the inner namespace without using the outer namespace first / at all), why does the standard forbid to d

相关标签:
2条回答
  • 2021-02-13 01:58

    Why make compilers implement it when you could just do

    namespace foo { namespace bar {
    
    }}
    
    0 讨论(0)
  • 2021-02-13 02:01

    I'm not sure "forbidden" is the right word - maybe it was just an oversight. It's a fairly small nice-to-have which isn't really a big deal.

    You could also take the point of view that the namespace foo isn't created yet when you write foo::bar, so allowing that syntax makes it look like foo was already created when it was not.

    You could also go further and request the ability to write class Foo::MyClass {... to define MyClass in namespace Foo, and the same for functions, variables, etc. But is this feature really necessary and solving any particular pressing problem?

    0 讨论(0)
提交回复
热议问题