C++智能指针入门
来源:互联网 发布:信托网络个人理财产品 编辑:程序博客网 时间:2024/04/30 17:04
上次,金山面试被问到智能指针,全然不知,静下心来好好学习学习。
C++ 提供四种智能指针auto_ptr, shared_ptr, unique_ptr, week_ptr.
用法:
#include <string>#include <memory>using namespace std;class report{private: string str;public: report(const string s):str(s) //构造方法 { cout<<"1 report Object has been build!"<<endl; } ~report() { cout<<"3 report Object deleted!"<<endl; } void talk() { cout<<str<<endl; }};int main(){ string talk="2 hello,this is a test!"; { auto_ptr<report> ptr(new report(talk)); ptr->talk(); } { shared_ptr<report> ptr(new report(talk)); ptr->talk(); } { unique_ptr<report> ptr(new report(talk)); ptr->talk(); } return 0;}
0 0
- C++智能指针入门
- 智能指针入门
- c++:智能指针
- C++:智能指针
- 【C++】智能指针
- 【C++】智能指针
- C++PJ智能指针
- 【c++】智能指针
- 【C++】智能指针auto_ptr
- C++,智能指针
- C++,boost智能指针
- 智能指针模拟C
- [C++]智能指针
- 【C++】 浅析智能指针
- C++_智能指针
- C++:初识智能指针
- C++::智能指针
- 【C++】智能指针
- 顽皮哥教你做达人脚本
- Lua初识之LuaStdio使用方法
- Web控件和HTML控件
- 开发Android调试时logcat不显示输出错误信息的解决办法
- 企业如何做好微信营销
- C++智能指针入门
- html5相较于以前版本不同之处
- Swing JTable例子(如何创建一个JTable)
- MarchingCubes算法提取等值面的基本原理
- maven tomcat eclipse 配置 debug
- PHP解压缩zip文件,使用类ZipArchiv
- Mysql数据库优化系列(四)------表的优化与列类型选择
- 二十四、oracle pl/sql 变量
- 小月带你种太阳