加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – “std :: make_shared()”值是否初始化我的POD?

发布时间:2020-12-16 03:16:09 所属栏目:百科 来源:网络整理
导读:std :: make_shared POD()值初始化我的POD? 如果是,这是否符合标准? 如果没有(我怀疑),有没有办法呢?我猜std :: make_shared POD(POD())会做,但是我应该做什么? 解决方法 是的,这是值得注意的,这是由标准保证的: §20.7.2.2.6,2:(关于make_shared) Effe
std :: make_shared< POD>()值初始化我的POD?

如果是,这是否符合标准?

如果没有(我怀疑),有没有办法呢?我猜std :: make_shared< POD>(POD())会做,但是我应该做什么?

解决方法

是的,这是值得注意的,这是由标准保证的:

§20.7.2.2.6,2:(关于make_shared)

Effects: Allocates memory suitable for an object of type T and constructs an object in that memory via the placement new expression ::new (pv) T(std::forward<Args>(args)...).

和§5.3.4,15:

A new-expression that creates an object of type T initializes that object as follows:
— If the new-initializer is omitted,the object is default-initialized (8.5); if no initialization is performed,the object has indeterminate value.
Otherwise,the new-initializer is interpreted according to the initialization rules of 8.5 for directinitialization.

因此,它将直接初始化为新的POD().

§8.5,16:

The semantics of initializers are as follows. […]
— If the initializer is (),the object is value-initialized.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读