smart_ptr智能指针的简单实现
来源:互联网 发布:网络公关服务公司 编辑:程序博客网 时间:2024/06/05 18:38
//// Created by yudw on 2017/8/7.//#pragma oncenamespace yudw{ template <typename T> class smart_pointer { public: // 需要显示构造 explicit smart_pointer(T* p): p_(p), use_(new size_t(1)){} // 拷贝构造 smart_pointer(const T &rhs): p_(rhs.p_), use_(rhs.use_){ ++*use_;} // 析构函数 ~smart_pointer() { if(--*use_ ==0) { delete p_; } } T* operator -> () const{ return p_;} T& operator * () const{ return *p_;} private: T* p_; // 指针 size_t* use_; // 引用计数 };}
阅读全文
1 0
- smart_ptr智能指针的简单实现
- <Boost> smart_ptr智能指针
- Boost.smart_ptr智能指针
- boost.Smart_ptr中智能指针
- boost.smart_ptr-智能指针scoped_ptr
- boost.smart_ptr-智能指针scoped_array
- boost.smart_ptr-智能指针scoped_array
- boost.smart_ptr-智能指针scoped_ptr
- boost.smart_ptr-智能指针scoped_ptr
- boost.smart_ptr-智能指针scoped_ptr
- boost::smart_ptr之智能指针
- 智能指针的简单实现
- 智能指针的简单实现
- 智能指针的简单实现
- 智能指针的简单实现
- 智能指针原理,并实现一个简单的智能指针
- 智能指针Boost.smart_ptr学习2--scoped_ptr
- 智能指针Boost.smart_ptr学习3--scoped_array
- python获取IP
- 设计模式之外观模式
- hdu2582 f(n) 找规律 素数筛
- 移动端头部文件详解(二)
- winform项目的app.config和exe.config文件
- smart_ptr智能指针的简单实现
- 一起来读Greenplum/Deepgreen执行计划
- lvs+keepalived高可用
- JNI 方法
- 站内信表结构设计
- dede:list和dede:arclist有什么区别
- Java -version与实际配置版本JAVA_HOME不一致
- MySQL 5.7.18的安装与主从复制
- dedecms的dede:list和dede:arclist分页问题(包括列表序号)