c – 类范围内的限定名称查找

引用自3.4.3.1/1:

If the nested-name-specifier of a qualified-id nominates a class, the
name specified after the nested-name-specifier is looked up in the
scope of the class

但进一步在3.4.3.1/1中说:

The name shall represent one or more members of that class or of one
of its base classes

并且3.3.8 / 1表示:

The potential scope of a name declared in a class consists not only of
the declarative region following the name’s point of declaration, but
also of all function bodies, default arguments,
exception-specifications, and brace-or-equal-initializers of
non-static data members in that class (including such things in nested
classes).

这意味着基类不包含在派生类范围中. 3.4.3.1/1应改为:

If the nested-name-specifier of a qualified-id nominates a class, the
name specified after the nested-name-specifier is looked up in the
scope of the class and in the scope of it base classes.

我对吗?

最佳答案 不,你不对.

您忘记的是,它指定了类的范围内的名称查找包括查看在所述类的直接基础中声明的名称,如10.2p5中所述.

10.2p5 Member name lookup [class.member.lookup]

Otherwise (ie., C does not contain a declaration of for the resulting declaration set is empty), S(F,C) is initialliy empty. If C has base classes, calculate the lookup set for f in each direct base class subobject B_i and merge each suck lookup set S(F,B_i), in turn into S(F,C).

简单的解释

之前的引用可能看起来过于复杂,但是它描述了在C的范围内查找名称f的方法.如果C中的声明没有名称为f,则搜索将继续包括在任何直接基础中声明的名称. C.

(注意:措辞是递归的,如果在C的直接基础中找不到名称f,则C的基数的潜在基数也在搜索f)

点赞