C++核心準(zhǔn)則R.23: 使用make_unique構(gòu)建unique_ptr

R.23: Use?make_unique()?to make?unique_ptrs
R.23:?使用make_unique構(gòu)建unique_ptr
Reason(原因)
For convenience and consistency with?shared_ptr.
出于習(xí)慣。保持和shared_ptr用法的一致性。
Note(注意)
make_unique()?is C++14, but widely available (as well as simple to write).
make_unique()是C++14引入的功能,但是可以廣泛使用(也很容易自己寫一個(gè))
Enforcement(實(shí)施建議)
(Simple) Warn if a?unique_ptr?is constructed from the result of?new?rather than?make_unique.
(簡單)如果unique_ptr從new得到的結(jié)果構(gòu)建而不是使用make_uinque,報(bào)警。
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r23-use-make_unique-to-make-unique_ptrs
覺得本文有幫助?請(qǐng)分享給更多人。
關(guān)注微信公眾號(hào)【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
評(píng)論
圖片
表情
