前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则R.23: 使用make_unique构建unique_ptr

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

作者头像
面向对象思考
发布2020-04-14 16:40:39
4321
发布2020-04-14 16:40:39
举报

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


觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

面向对象开发,面向对象思考!

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-04-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • R.23: Use make_unique() to make unique_ptrs
  • Reason(原因)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档