C++核心准则R.23: 使用make

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


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

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

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

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


分享到:


相關文章: