C 11委托执行程序比调用init函数的C 03 ctors更糟糕?

[这个问题已被高度编辑;恕我直言,我已将编辑移到下面的答案中]

从07年7月11日

This [new delegating constructors feature] comes with a caveat: C++03 considers an object to be constructed when its constructor finishes executing,but C++11 considers an object constructed once any constructor finishes execution. Since multiple constructors will be allowed to execute,this will mean that each delegating constructor will be executing on a fully constructed object of its own type. Derived class constructors will execute after all delegation in their base classes is complete.”

这是否意味着委托链为ctor代理链中的每个链接构建一个唯一的临时对象?只是为了避免简单的init函数定义,这种开销不值得额外的开销.

免责声明:我问这个问题,因为我是一名学生,但迄今为止的答案都是不正确的,并且表明缺乏对所提及的研究和/或理解.我对此感到沮丧,结果我的编辑和评论匆匆而过,主要是通过智能手机.请原谅我希望我在下面的答案中尽量减少了这一点,我已经了解到,我的意见中需要谨慎,完整和清楚.

解决方法

不,他们是等同的.委托构造函数的行为就像一个普通的成员函数,它作用于由前一个构造函数构造的Object.

我在proposal for adding delegating constructors中找不到明确支持这一点的信息,但在一般情况下创建副本是不可能的.某些类可能没有复制构造函数.

在第4.3节 – 对§15的修改中,建议对标准状态的更改:

if the non‐delegating constructor for an object has completed execution and a delegating constructor for that object exits with an exception,the object’s destructor will be invoked.

这意味着委托构造函数在完全构造的对象上工作(取决于如何定义它),并允许实现使委托函数像成员函数一样工作.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...