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

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.

相关文章

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