C++核心准则R.23: 使用make_unique构建unique_ptr

R.23: Use make_unique() to make unique_ptrs

R.23: 使用make_unique构建unique_ptr

 

Reason(原因)

For convenience and consistency with shared_ptr.

出于习惯。保持和shared_ptr用法的一致性。

 

Note(注意)

make_unique() is C++14, but widely available (as well as simple to write).

make_unique()是C++14引入的功能,但是可以广泛使用(也很容易自己写一个)

 

Enforcement(实施建议)

(Simple) Warn if a unique_ptr is constructed from the result of new rather than make_unique.

(简单)如果unique_ptr从new得到的结果构建而不是使用make_uinque,报警。

 

原文链接

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r23-use-make_unique-to-make-unique_ptrs


 

觉得本文有帮助?欢迎点赞并分享给更多的人。

阅读更多更新文章,请关注微信公众号【面向对象思考】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值