per :
从类型C([class.inhctor.init])继承的构造函数)
具有“引用CV1 P”类型的第一个参数(包括这样的A
从模板实例化的构造函数)不包括在一组
如果构造CV2 d的对象,则候选人功能
参数列表完全具有一个参数,C引用与P相关
和p与d。
相关
。
struct P;
struct C { C(); C(const P&); };
struct P : C { using C::C; };
struct D : P {};
D d{ P() };
P与 将参考与 P
和 P
引用与 d
相关。并且有一个从类型 c
继承的构造函数,该构建器具有“引用 cv1 p
”的第一个参数。当构造类型 cv d
的对象时,参数列表完全具有一个参数,该参数为 p()
- 然后将此继承的构造函数从一组候选函数中排除。
我的示例是否匹配措辞的打算?我是否正确理解和解析了措辞?另外,关于这一点还有其他措辞(继承复制/移动构造函数)吗?
Per § 12.2.2.1 [over.match.funcs.general]/9-sentence-2:
A constructor inherited from class type C ([class.inhctor.init]) that
has a first parameter of type “reference to cv1 P” (including such a
constructor instantiated from a template) is excluded from the set of
candidate functions when constructing an object of type cv2 D if the
argument list has exactly one argument and C is reference-related to P
and P is reference-related to D.
I am just trying to understand this paragraph and somehow conduct an example that matches the wording then I want to apply that example to the paragraph:
struct P;
struct C { C(); C(const P&); };
struct P : C { using C::C; };
struct D : P {};
D d{ P() };
From the above example: C
is reference-related to P
and P
is reference-related to D
. And there's a constructor inherited from class type C
that has a first parameter of type “reference to cv1 P
”. And when constructing an object of type cv D
-and the argument list has exactly one argument which is P()
- then this inherited constructor is excluded from the set of candidate functions.
Does my example match what the wording intends? And Do I understand and parse the wording correctly? Also, Is there any other wording regarding this point (inheriting copy/move constructors)?
发布评论
评论(1)
此示例与继承构造函数无关:即使使用c :: c :: c; 删除了
c(const p&);
and,它即使可以使用。它是通过为其一个子对象提供值(基本
p
)的值来进行汇总d
的初始化。请注意,尽管效果与人们期望的事情相似,但没有“编译器生成的
d :: D :: D(const p&)
”。在C ++ 17中,更改为d d((p()));
失败,但是C ++ 20也可以汇总初始化。This example has nothing to do with inheriting constructors: it works even with either or both of
C(const P&);
andusing C::C;
removed. It’s doing aggregate initialization of aD
by supplying a value for its one subobject (the baseP
).Note that there is no “compiler-generated
D::D(const P&)
”, although the effect is similar to what one might expect it to do. In C++17, changing toD d((P()));
fails, but C++20 lets that be aggregate initialization too.