shared_ptr

复制代码
 1 #include <boost/shared_ptr.hpp>
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int main(int argc, char const *argv[])
 6 {
 7 
 8     boost::shared_ptr<int> i1(new int(255));
 9 
10     cout<<"use_count:"<<i1.use_count()<<endl;
11     int * p = i1.get();
12 
13     cout<<"use_count:"<<i1.use_count()<<endl;
14     cout<<"i1:"<<*p<<endl;
15 
16     boost::shared_ptr<int> i2 = i1;    
17     cout<<"use_count:"<<i1.use_count()<<endl;
18     *i2.get() = 88;
19     cout<<*i1.get()<<endl;
20 
21     i2.reset();    
22     cout<<"use_count:"<<i1.use_count()<<endl;
23 
24     return 0;
25 }
复制代码

 

posted @   三岁玩童  阅读(39)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-01-02 wheel: function&bind
点击右上角即可分享
微信分享提示