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

前端 未结 4 1452
南旧
南旧 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:51

    It is called as Qualified name lookup in C++.

    It means that the layer namespace being referred to is the one off the global namespace, rather than another nested namespace named layer.

    For Standerdese fans:
    $3.4.3/1

    "The name of a class or namespace member can be referred to after the :: scope resolution operator (5.1) applied to a nested-name-specifier that nominates its class or namespace. During the lookup for a name preceding the :: scope resolution operator, object, function, and enumerator names are ignored. If the name found is not a class-name (clause 9) or namespace-name (7.3.1), the program is ill-formed."

提交回复
热议问题