C ++中的多个命名空间声明 [英] Multiple namespace declaration in C++

查看:125
本文介绍了C ++中的多个命名空间声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

替换以下内容是合法的:

Is it legal to replace something like this:

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


$ b

with something like this:

namespace foo::bar {
   baz();
}

推荐答案

您可以将命名空间合并为一个名称并使用新名称(例如Foobar)。

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

这篇关于C ++中的多个命名空间声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆