前导::在“使用命名空间:: 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.