关于对象生存期的开始,C ++标准意味着什么? [英] What does the C++ standard mean regarding object lifetime begins?

查看:88
本文介绍了关于对象生存期的开始,C ++标准意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在3.8.1节的n3690 C ++标准中,有以下文字:

In the n3690 C++ standard in section 3.8.1 there is this text:

The lifetime of an object of type T begins when:
— storage with the proper alignment and size for type T is obtained, and
— if the object has non-trivial initialization, its initialization is complete.

假设有一个用户定义的构造函数.

Assume that there is a user defined constructor.

最后一句话是什么意思?是在初始化程序列表完成初始化之后还是在构造函数主体完成运行之后?还是最后一句话意味着其他意思?

What does the last sentence mean? Is it when the initializer list has finished initializing or is it when constructor body has finished running? Or does the last sentence mean something else?

推荐答案

12.6.2,[class.base.init],项目6,列出了初始化步骤,这是最后一步:

12.6.2, [class.base.init], item 6, lists the steps of initialization, and this is the final one:

最后,执行构造函数主体的 compound-statement .

因此,一旦执行主体,初始化就完成了.

So once the body has executed, initialization is complete.

这篇关于关于对象生存期的开始,C ++标准意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆