Robert Mason Robert Mason - 5 days ago 5
C++ Question

Multiple namespace declaration in C++

Is it legal to replace something like this:

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


with something like this:

namespace foo::bar {
baz();
}


?

Answer

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();
}
Comments