前导::在“使用命名空间:: X"中的含义是什么?在C ++中 [英] What does a leading :: mean in "using namespace ::X" in C++

查看:63
本文介绍了前导::在“使用命名空间:: X"中的含义是什么?在C ++中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释以下命名空间用法之间的区别吗?

can somebody explain me the difference between the following namespace usages:

using namespace ::layer::module;

using namespace layer::module;

是什么原因导致在layer之前出现另外的::?

What causes the additional :: before layer?

推荐答案

如果在以下环境中使用它会有所不同:

There would be a difference if it was used in a context such as:

namespace layer {
    namespace module {
        int x;
    }
}

namespace nest {
    namespace layer {
        namespace module {
            int x;
        }
    }
    using namespace /*::*/layer::module;
}

使用开头的::,第一个x在using指令后可见,如果没有它,则第二个xnest::layer::module内部的可见.

With the initial :: the first x would be visible after the using directive, without it the second x inside nest::layer::module would be made visible.

这篇关于前导::在“使用命名空间:: X"中的含义是什么?在C ++中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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