R.33: 表达函数会重置widget时,使用unique_ptr<widget>&作参数。
Using unique_ptr in this way both documents and enforces the function call's reseating semantics.
以这种方式使用unique_ptr可以从文档和实现两个方面强制函数调用的重置语义。
Note(注意)
"reseat" means "making a pointer or a smart pointer refer to a different object."
“重置”的意思是使指针或者智能指针参照另外一个对象。
Example(示例)
void reseat(unique_ptr<widget>&); // "will" or "might" reseat pointer
void thinko(const unique_ptr<widget>&); // usually not what you want
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r32-take-a-unique_ptrwidget-parameter-to-express-that-a-function-assumes-ownership-of-a-widget
觉得本文有帮助?请分享给更多人。
关注微信公众号【面向对象思考】轻松学习每一天!
面向对象开发,面向对象思考!