2011年计算机等级考试二级C语言辅导实例编程(16)

2014-10-28 20:30:18 · 作者: · 浏览: 225

  实现一个简单的智能指针


  01// helloworld.cpp : 定义控制台应用程序的入口点。


  02//


  03


  04#include "stdafx.h"


  05#include


  06using namespace std;


  07


  08//指针类


  09class I_Pointer{


  10private:


  11 int ref_count;


  12 int *p;


  13 I_Pointer(int *p): p(p), ref_count(1){}; //构造函数


  14 ~I_Pointer(){


  15 cout<<"Delete shared pointer"<


  16 }


  17friend


  18 class Has_Ptr;


  19};


  20


  21//有指针成员的类


  22class Has_Ptr{


  23private:


  编辑特别推荐: