effective C++ 条款十七解读
来源:互联网 发布:install ubuntu 编辑:程序博客网 时间:2024/06/06 03:52
以独立的语句讲newed对象放入智能指针
用下面一段代码来解释:
int priority();processWidget(shared_ptr(new Widget),priority());shared_ptr pWid=new Widget();processWidget(pwid,priority());上面第一段代码存在的问题主要是代码在调用函数processWidget的时候调用顺序可能是以下这种情况:1.new widget
2.priority()函数
3.把new widget放到shared_ptr之中。
当priority函数抛出异常的时候,那么资源就造成了泄露,所以需要我们采用第二种方式以独立的语句讲newed对象放入智能指针
阅读全文
0 0
- effective C++ 条款十七解读
- effective C++条款二十七解读
- Effective C++ 条款二解读
- effective C++ 条款三 解读
- effective c++ 条款4解读
- effective C++条款五解读
- effective C++ 条款六解读
- effective C++ 条款八解读
- effective C++ 条款九解读
- effective C++ 条款十解读
- effective C++ 条款十一解读
- effective C++ 条款十二解读
- effective C++ 条款十三解读
- effective c++ 条款十四解读
- effective C++条款十五解读
- effective C++ 条款十六解读
- effective C++ 条款十八解读
- effective C++条款十九解读
- Asteroids
- Hadoop学习笔记(一)
- 关于spring的配置文件总结
- Java的插入排序
- IP 地址冲突检测(解决某种情况下 arp 机制无效的问题)
- effective C++ 条款十七解读
- MYSQL报错注入方法整理
- Linux---gcc 编译
- MySQL的存储过程
- c3p0在hibernate中的配置
- spring之Bean的生命周期
- Linux内核编译运行
- 客户流失预测--基于R语言C5.0
- [POJ