[over.match.funcs.general]/9和继承的复制/移动构造函数上的问题

发布于 2025-01-25 11:12:42 字数 739 浏览 2 评论 0 原文

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

比忠 2025-02-01 11:12:42

此示例与继承构造函数无关:即使使用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&); and using C::C; removed. It’s doing aggregate initialization of a D by supplying a value for its one subobject (the base P).

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 to D d((P())); fails, but C++20 lets that be aggregate initialization too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文