boost库的智能指针shared_ptr结合容器vector的使用
来源:互联网 发布:pc6软件下载指南 编辑:程序博客网 时间:2024/05/17 08:55
将n个shared_ptr放在vector中,vector会保持每个shared_ptr的引用;vector销毁时,shared_ptr会自动销毁所持对象,释放内存
#include <iostream>#include <boost/shared_ptr.hpp>#include <vector>using namespace std;class A{public:A(int i):num(i){}int getNum() { return num; }~A() { cout << num << " destroy" << endl; }private:int num;};int main(){vector<boost::shared_ptr<A> > vsa;for(int i = 0; i < 5; ++i){boost::shared_ptr<A> x(new A(i));vsa.push_back(x);}for(size_t i = 0; i < vsa.size(); ++i){std::cout << vsa[i]->getNum() << " ";}cout << endl;}
- boost库的智能指针shared_ptr结合容器vector的使用
- boost智能指针shared_ptr使用要注意的几个问题
- shared_ptr和weak_ptr智能指针结合使用的一个实例
- 智能指针tr1::shared_ptr、boost::shared_ptr使用
- 容器vector的resize操作 & 智能指针shared_ptr的reset操作
- boost中的智能指针shared_ptr的指针管理
- Boost智能指针:shared_ptr
- 智能指针boost::shared_ptr
- 智能指针boost::shared_ptr
- Boost智能指针:shared_ptr
- std::auto_ptr boost::shared_ptr智能指针的应用
- 智能指针shared_ptr组件的使用
- c++智能指针的使用,auto_ptr,shared_ptr
- 关于动态分配vector指针和使用shared_ptr的vector指针
- C++ Primer : 第十二章 : 动态内存之shared_ptr与new的结合使用、智能指针异常
- boost库之shared_ptr库,智能指针
- boost库在工作(8)引用计数的智能指针shared_ptr之一
- boost库在工作(9)引用计数的智能指针shared_ptr之二
- 简约而不简单的拟物化设计
- 数据迁移:数据库软件升级10.2.0.4到10.2.0.5
- centos 6.2 下安装 wireshark
- Win ce6 Eboot 中加入开机画面
- 卸载webmin
- boost库的智能指针shared_ptr结合容器vector的使用
- 作业调度框架 Quartz 学习笔记(四) -- 接收参数和维护状态
- 数据迁移:务数据导出,导入到当前环境
- wordpress获得主题的相对路径
- JFreeChart的使用
- 关于oracle rowid的一些内容
- [Java]读取文件方法大全
- Poj 3253 - Fence Repair 最小堆
- android4.0去掉锁屏和休眠