boost库之shared_ptr库,智能指针
来源:互联网 发布:氧气听书软件电脑版 编辑:程序博客网 时间:2024/06/05 01:58
使用说明:
1. shared_ptr<int>默认值是NULL
2. 赋值
3.reset()
4. 函数返回share_ptr<int>为NULL
代码:
#include <iostream>#include <string>#include <boost/shared_ptr.hpp>using namespace std;using namespace boost;//4. return shared_ptr<int> is nullshared_ptr<int> func(){ return shared_ptr<int>(); }int main(int argc, char* argv[]){ //1. shared_ptr<int> default is null shared_ptr<int> ptr; //1.1 if (ptr == NULL) cout<<"1. \"shared_ptr<int> ptr\" is null"<<endl; else cout<<"1. \"shared_ptr<int> ptr\" is not null"<<endl; //2. assgin value to share_ptr<int> ptr = shared_ptr<int>(new int(100)); //2.1 cout<<"2. ptr:"<<ptr<<", *ptr:"<<*ptr<<endl; //3. shared_ptr<int> reset() is null ptr.reset(); //3.1 if (ptr == NULL) cout<<"3. \"ptr.reset()\" is null"<<endl; else cout<<"3. \"ptr.reset()\" is not null"<<endl; //4.1 if (func() == NULL) cout<<"4. \"func() return share_ptr<int>()\" is null"<<endl; else cout<<"4. \"func() return share_ptr<int>()\" is not null"<<endl; return 0;}
输出结果:
参考资料:
boost::shared_ptr class example:http://www.boost.org/doc/libs/1_53_0/libs/smart_ptr/shared_ptr.htm#example
0 0
- boost库之shared_ptr库,智能指针
- Boost库中的智能指针 shared_ptr智能指针
- 【Boost】boost库中智能指针——shared_ptr
- Boost智能指针:shared_ptr
- 智能指针boost::shared_ptr
- 智能指针boost::shared_ptr
- Boost智能指针:shared_ptr
- 浅析boost之智能指针—shared_ptr
- boost智能指针之shared_ptr和weak_ptr
- Boost库学习—智能指针Shared_ptr学习01
- 详解Boost库智能指针(shared_ptr && scoped_ptr && weak_ptr )
- boost库:智能指针(auto_ptr、scoped_ptr、shared_ptr)浅谈
- boost库在工作(9)引用计数的智能指针shared_ptr之二
- boost库在工作(9)引用计数的智能指针shared_ptr之二
- BOOST库 之 智能指针
- Boost智能指针—shared_ptr
- C++ boost智能指针shared_ptr
- boost智能指针系列:shared_ptr
- POJ_3414_Pots
- MySQL之Master-Master配置
- 【剑指Offer面试题】 九度OJ1522:包含min函数的栈
- 三种线性排序算法(计数、基数、桶排序)的简单实现
- R语言:初试logitstic
- boost库之shared_ptr库,智能指针
- 递归计算N阶乘
- Angular新手容易碰到的坑,随时更新,欢迎订阅
- ExtJS入门
- 古月居关于ROS的导航部分要抽空学习一下
- java NIO教程
- redis学习小结
- 搭建MySql的Master/Slave架构
- bc第六场Goffi and GCD