What does a leading :: mean in “using namespace ::X” in C++

前端 未结 4 1428
南旧
南旧 2020-12-31 03:51

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

using namespace ::layer::module;

and

using namespa

4条回答
  •  礼貌的吻别
    2020-12-31 04:48

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

    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.

提交回复
热议问题