Multiple namespace declaration in C++

后端 未结 7 1367
无人共我
无人共我 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:03

    You can combine namespaces into one name and use the new name (i.e. Foobar).

    namespace Foo { namespace Bar {
        void some_func() {
            printf("Hello World.");
        }
    }}
    
    namespace Foobar = Foo::Bar;
    
    int main()
    {
        Foobar::some_func();
    }
    

提交回复
热议问题