从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.
原文地址:https://www.jb51.cc/c/113838.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。