智能指针使用指南
来源:互联网 发布:有哪些动画培训班知乎 编辑:程序博客网 时间:2024/06/04 19:09
智能指针使用指南
### SmartPtr Guideline
void f( widget* ); (a)void f( widget& ); (b)void f( unique_ptr<widget> ); (c)void f( unique_ptr<widget>& ); (d)void f( shared_ptr<widget> ); (e)void f( shared_ptr<widget>& ); (f)
Guideline #1:
Don’t pass a smart pointer as a function parameter unless you want to use or manipulate the smart pointer itself, such as to share or transfer ownership.
Guideline #2:
Prefer passing objects by value, *, or &, not by smart pointer.
Guidline #3:
As usual, use a * if you need to express null (no widget), otherwise prefer to use a &; and if the object is input-only, write const widget* or const widget&.
Guideline #4:
Express a “sink” function using a by-value unique_ptr parameter.
ref:
https://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/amp/
0 0
- 智能指针使用指南
- Qt智能指针使用指南 帮助篇
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- 智能指针
- SCI/EI论文写作常用句型
- [构造] UNR #1 Jakarta Skyscrapers
- UIButton超出UIView边界不可点击
- [李景山php]thinkphp核心源码注释|Html.class.php
- 处理某些目录网页不能被calibre解析的方法
- 智能指针使用指南
- 配置python的pandas包
- [李景山php]thinkphp核心源码注释|File.class.php
- APACHE-CXF demo
- 基于海思的H265码流实时传输系统设计
- Bitmap的四种属性,与每种属性对应的大小
- [下界最小流] UNR #1 奇怪的线段树
- mysql workbench 错误 No database selected Select the default DB to be used by double-clicking its nam
- APUE 7-13 longjmp对各类对象的影响