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