且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么不在这里考虑std :: begin / end?

更新时间:2023-02-20 17:44:42

using-directive的方式的工作是( [namespace.udir] / 2 ):


using-directive 指定可以使用指定命名空间
中的名称在 using-directive 之后出现 using-directive 的范围内。在非限定名称查找
([basic.lookup.unqual])期间,名称显示为在
中声明最近的封闭命名空间,其中包含
using-directive 和指定的命名空间。 [注意:在此上下文中,
包含表示直接或间接包含。 - 结束注释]

A using-directive specifies that the names in the nominated namespace can be used in the scope in which the using-directive appears after the using-directive. During unqualified name lookup ([basic.lookup.unqual]), the names appear as if they were declared in the nearest enclosing namespace which contains both the using-directive and the nominated namespace. [ Note: In this context, "contains" means "contains directly or indirectly". — end note ]

使用namespace :: std; $ c为此,$ c>使 :: std 的成员可见,就好像它们是全局命名空间的成员一样。因此,根据正常的非限定查找规则,它们在命名空间工具箱中具有相同名称的任何内容都是隐藏的。

using namespace ::std; causes the members of ::std to be visible, for this purpose, as if they were members of the global namespace. They are therefore hidden, per the normal unqualified lookup rules, by anything with the same name in the namespace Toolbox.