shared_ptr
来源:互联网 发布:站长工具js格式化 编辑:程序博客网 时间:2024/06/10 15:01
template <class T> class SmartPointer {public: SmartPointer(T * ptr) { ref = ptr; ref_count = (unsigned*)malloc(sizeof(unsigned)); *ref_count = 1; } SmartPointer(SmartPointer<T> & sptr) { ref = sptr.ref; ref_count = sptr.ref_count; ++*ref_count; } SmartPointer<T> & operator=(SmartPointer<T> & sptr) { if (this != &sptr) { ref = sptr.ref; ref_count = sptr.ref_count; ++*ref_count; } return *this; } ~SmartPointer() { --*ref_count; if (*ref_count == 0) { delete ref; free(ref_count); ref = NULL; ref_count = NULL; } } T getValue() { return *ref; }protected: T * ref; unsigned * ref_count;};
0 0
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr()
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- shared_ptr
- Linux中的Apache安装
- oracle event 2
- 两分钟让你明白cocos2dx的屏幕适配策略
- Apache服务器的源码包安装及配置
- 且听风吟
- shared_ptr
- macos下如何配置ssh无密码登录
- 【剑指Offer】鸟瞰50题之31 - 40题
- 学习spring MVC的步骤?
- 关于C++ const 的全面总结
- junit 笔记(一)
- ECSHOP 首页根据ID调用单篇文章代码
- Json解析
- window批处理-2.@