什么时候在构造函数的类定义中通过普通查找找不到 mem-initializer-id?

When is it the case that a mem-initializer-id is not found by ordinary lookup in the constructor's class definition?

本文关键字:查找 找不到 mem-initializer-id 构造函数 定义 什么时候      更新时间:2023-10-16

给定这个片段

class Base
{
public:
    Base(){};
};
class Derived : public Base
{
public:
    Derived();
};
Derived::Derived() :Base() {}

并考虑到§12.6.2/2(我的重点)中的这一声明

mem初始值设定项id中,会查找一个初始的非限定标识符在构造函数类的范围内,如果在scope,在包含构造函数释义

我认为在Derived构造函数的定义中查找名称Base是在Derived类定义中找到的

我只是想知道,除了12.6.2/3中给出的例子之外,是否还有其他更具体的例子,其中在构造函数的类中找不到mem初始值设定项id

mem初始值设定项id必须命名构造函数的类,该类是构造函数的类,或者该类的直接或虚拟基。如果它是一个实际的类名(无论是派生类还是基类),它将在类的作用域内被发现为注入的类名。如果它是一个数据成员,那么名称查找显然会在类的范围内找到它。这就留下了一个typedef,但这也是12.6.2/3:中给出的例子

class Base { };
class Derived : public Base
{
public:
    Derived();
};
using BaseAlias = Base;
Derived::Derived() : BaseAlias() {}

我只是想知道,除了12.6.2/3中给出的例子之外,是否还有其他更具体的例子,其中在构造函数的类中找不到mem初始值设定项id

一个比使用简单别名typedef/using作为§12.6.2/p3:基类的例子更实用的例子

#include <type_traits>
struct Base {};
struct Base2 {};
struct Derived : Base, Base2
{
    Derived();
};
using namespace std;
Derived::Derived() : conditional_t<true, Base, Base2>{} {}
//                   ~~~~~~~~~~~~^