13.9Write a smart pointer (smart_ptr) class

template<class T>class SmartPoint{
public:
SmartPoint(T *ref){
ref_ = ref;
count_ = (unsigned int *)malloc(sizeof(unsigned int ));
*count_ = 1;
}
SmartPoint(SmartPoint<T> &sptr){
ref_ = sptr.ref_;
count_ = sptr.count_;
++(*count_);
}
SmartPoint<T>& operator =(SmartPoint<T> &sptr)
{
if(this != sptr){
ref_ = sptr.ref_;
count_ = sptr.count_;
++(*count_);
}
return *this;
}
~SmartPoint()
{
--(*count_);
if(*count_ == 0)
{
delete ref_;
free(count_);
ref_ = NULL;
count_ = NULL;
} }
T getValue(){
rturn *ref_;
}
private:
T* ref_;
unsigned int *count_;
};

  

最新文章

  1. Dijkstra搜索算法
  2. HTTP请求错误大全
  3. MVC ActionResult -- JavaScriptResult,JsonResult
  4. Linux学习系列之Linux入门(三)gcc学习
  5. eclipse4.2.1插件安装(二)之Eclipse HTML Editor
  6. 数缘社区上对libtom的介绍,贴过来先
  7. nginx日志格式
  8. Oracle EBS-SQL (INV-6):检查监督帐户别名处理.sql
  9. 一年三篇IF大于7的牛人告诉你怎么写SCI
  10. 【最短路】 poj 2387
  11. 读书笔记 effective c++ Item 25 实现一个不抛出异常的swap
  12. Managing Spark data handles in R
  13. 详解用em替换px
  14. set命令详解
  15. 使用Http-Repl工具测试ASP.NET Core 2.2中的Web Api项目
  16. ZOJ 3987 Numbers(Java枚举)
  17. Web.config的Release版本和Debug版本不一样的奥秘
  18. CentOS7安装OpenStack(Rocky版)-09.安装Cinder存储服务组件(控制节点)
  19. 中国的 Python 量化交易工具链有哪些
  20. Vim技能修炼教程(7) - 可视模式

热门文章

  1. UML建模之活动图介绍(Activity Diagram)
  2. LibCurl编程手册以及代码实例
  3. Linux中断分层技术
  4. 笔记:java并发实践2
  5. 批量将文件转换为UTF-8无BOM格式
  6. 【转】opencv检测运动物体的基础_特征提取
  7. JS-异常处理
  8. 【自由谈】城域网IPv6过渡技术——4v6场景技术总结(1)
  9. 【更新日志】售后CP更新日志
  10. hdu2209翻纸牌游戏