gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:10:07 26 4
gpt4 key购买 nike

有一段来自 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 的任何直接基中声明的那些名称。

( 注意:写法是递归的,如果名字f没有在C的直接基类中找到,潜在的基类C 的基数也在搜索 f )

关于c++ - 类范围内的限定名称查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24095412/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com