C++ STL智能指针(三)
来源:互联网 发布:c语言搜索引擎 编辑:程序博客网 时间:2024/05/29 13:48
#include <iostream>#include <memory>using std::cout;using std::cin;using std::endl;using std::auto_ptr;class WebSite{public: WebSite() { cout << "WebSite" << endl; } ~WebSite() { cout << "~WebSite" << endl; }};int main(){ /* reset()函数的用法 WebSite *pCpp = new WebSite; auto_ptr<WebSite> pautoWebSite; pautoWebSite.reset(pCpp); cout << pCpp << " " << pautoWebSite.get() << endl; */ auto_ptr<WebSite> autoPtr1(new WebSite); auto_ptr<WebSite> autoPtr2(new WebSite); cout << autoPtr1.get() << endl; cout << autoPtr2.get() << endl; autoPtr1 = autoPtr2;//发生了三件事:1.autoPtr1析构为0,2.autoPtr2船值给autoPtr1,3.autoPtr2析构为0; cout << autoPtr1.get() << endl; cout << autoPtr2.get() << endl; auto_ptr<WebSite> autoPtr3(autoPtr1); //1.autoPtr1析构为0, 2.将值传递给autoPtr3 cout << autoPtr1.get() << endl; //输出为0 cout << autoPtr3.get() << endl; //输出为autoPtr1之前的值 return 0;}
0 0
- C++ STL智能指针(三)
- C/C++: stl 和 boost 中的智能指针
- stl智能指针auto_ptr
- STL--智能指针(auto_ptr)
- STL 智能指针
- stl智能指针auto_ptr
- STL之智能指针
- STL之智能指针
- auto_ptr STL智能指针
- 【STL】智能指针auto_ptr
- 智能指针(STL)
- [STL] STL不支持智能指针
- C++STL位标志、智能指针与异常处理
- 智能指针与STL容器
- STL之auto_ptr智能指针
- c++ stl auto_ptr智能指针
- C++ STL 智能指针(二)
- (未完)【C/C++】C++智能指针
- Android 获取View的位置属性
- ios_ui 学习demo以及参考网站
- Android中FTP服务器、客户端搭建以及SwiFTP、ftp4j介绍
- Java中HashMap详解
- 证明周期
- C++ STL智能指针(三)
- 浅谈神经网络
- dialogArguments property
- 关于元注解@Inherited()再探究
- 设计模式-开放封闭
- Wake-On-Lan with Python 3.x
- 展现报表同时后台导出excel
- 局域网访问VMware中虚拟机
- 第三天:基本数据结构--队列