effective c++ 条款13
来源:互联网 发布:java violate关键字 编辑:程序博客网 时间:2024/05/17 07:03
为了防止资源泄露,请使用RAII (resource Acquisition is initialization),他们在构造函数中或的资源并在析构函数中 释放资源。
应用模板(类):
shared_ptr ;
shared_ptr 的构造函数已经声明为 explicit ,防止隐式类型转换。
用例:
#include<iostream>#include <string >#include <memory>using namespace std ;int main(){ string *Pts= new string("hi"); shared_ptr <string > p1(Pts); if (p1&& p1->empty() ) //判断p1 是否为空,是否指向一个空字符串 { *p1 = "hi"; //解引用 } cout<< *p1<<endl;}
0 0
- 《Effective C++》资源管理:条款13-条款15
- 【Effective C++】读书笔记 条款13~条款17
- Effective C++(条款13-17)
- Effective C++:条款01
- Effective C++:条款02
- Effective C++:条款03
- Effective C++:条款04
- Effective C++:条款05
- Effective C++:条款06
- Effective C++:条款07
- Effective C++:条款08
- 《effective C++》条款三
- 《effective C++》条款5
- 《effective C++》条款六
- Effective C++--经验条款
- Effective C ++ 条款34
- 《Effective C++》条款05
- 《Effective C++》条款06
- 【卷积神经网络-进化史】从LeNet到AlexNet
- Windows7 Update 一直检查更新怎么破? 转自知乎
- Android特效专辑(六)——仿QQ聊天撒花特效,无形装逼,最为致命
- [生存志] 第68节 平王纳媳诛伍奢
- velocity 跳出循环 break、stop
- effective c++ 条款13
- Java虚拟机的堆与栈
- coursera算法公开课练习题Interview(2)
- Java集合框架之迭代器(if与while语句)
- Makefile中=与:=的区别
- 正则表达式
- [STL]List的实现
- How to unlock user in DB
- Redis 4.0 新功能简介