Multiple namespace declaration in C++

后端 未结 7 1372
无人共我
无人共我 2020-12-28 17:30

Is it legal to replace something like this:

namespace foo {
   namespace bar {
      baz();
   }
}

with something like this:



        
7条回答
  •  孤独总比滥情好
    2020-12-28 18:15

    Pre C++17:

    No, it's not. Instead of a bunch of indented nested namespaces, it's certainly valid to put them on the same line:

    namespace Foo { namespace Bar { namespace YetAnother {
        // do something fancy
    } } } // end Foo::Bar::YetAnother namespace
    

    C++17 Update:

    You can now nest namespaces more cleanly in C++17:

    namespace Foo::Bar::YetAnother {
      // do something even fancier!
    }
    

提交回复
热议问题