Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么情况下在构造函数';什么是类定义?_C++_C++11_Language Lawyer - Fatal编程技术网

C++ 什么情况下在构造函数';什么是类定义?

C++ 什么情况下在构造函数';什么是类定义?,c++,c++11,language-lawyer,C++,C++11,Language Lawyer,鉴于这个片段 class Base { public: Base(){}; }; class Derived : public Base { public: Derived(); }; Derived::Derived() :Base() {} 并考虑§12.6.2/2(我的重点)中的这一陈述 在mem初始值设定项id中查找初始非限定标识符 在构造函数的类的范围内,如果未在该类中找到 范围,在包含构造函数的 定义 我想说,在派生的构造函数的定义中查找名称Base,可以在派生

鉴于这个片段

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

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

Derived::Derived() :Base() {}
并考虑§12.6.2/2(我的重点)中的这一陈述

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

我想说,在
派生的
构造函数的定义中查找名称
Base
,可以在
派生的
类定义中找到

我只是想知道,除了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() {}
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

对于§12.6.2/p3中的基类,一个比使用带有
typedef
/
的简单别名更实用的示例:

#include <type_traits>

struct Base {};
struct Base2 {};

struct Derived : Base, Base2
{
    Derived();
};

using namespace std;

Derived::Derived() : conditional_t<true, Base, Base2>{} {}
//                   ~~~~~~~~~~~~^
#包括
结构基{};
结构Base2{};
派生结构:Base,Base2
{
派生();
};
使用名称空间std;
派生的::派生的():条件的{}{}
//                   ~~~~~~~~~~~~^
我只是想知道,除了12.6.2/3中给出的例子之外,是否还有其他更具体的例子,在构造函数的类中找不到mem初始值设定项id

对于§12.6.2/p3中的基类,一个比使用带有
typedef
/
的简单别名更实用的示例:

#include <type_traits>

struct Base {};
struct Base2 {};

struct Derived : Base, Base2
{
    Derived();
};

using namespace std;

Derived::Derived() : conditional_t<true, Base, Base2>{} {}
//                   ~~~~~~~~~~~~^
#包括
结构基{};
结构Base2{};
派生结构:Base,Base2
{
派生();
};
使用名称空间std;
派生的::派生的():条件的{}{}
//                   ~~~~~~~~~~~~^

@AlanStokes这是一个注入类名称。我想说的是,名称
Base
是通过通常的查找在
派生的
类定义中找到的。12.6.2/3中的示例有什么问题?@T.C.可能OP认为这是人为的。我投票决定以不清楚的方式结束。@T.C.没问题。我觉得这有点做作。我上面复制的语句是这样写的,只是为了满足12.6.2/3示例中的代码,或者在类构造函数中找不到mem初始值设定项id的其他示例?@AlanStokes这是一个注入类名称。我要说的是,名称
Base
是通过通常的查找找到的,在
派生的
类定义中。12.6.2/3中的示例有什么问题?@T.C.可能OP认为这是人为的。我投票决定以不清楚的方式结束。@T.C.没问题。我觉得这有点做作。在这种情况下,我上面复制的语句是以这种方式编写的,只是为了满足12.6.2/3中示例中的代码,还是在类构造函数中找不到mem初始值设定项id的其他示例?