sonyhandle.h
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // sonyhandle.h
  3. //=====================================
  4. #ifndef HEADER_SONYHANDLE
  5. #define HEADER_SONYHANDLE
  6. //-------------------------------------
  7. #include"sony.h"
  8. //-------------------------------------
  9. class SonyHandle{
  10.   Sony* sp;
  11.   int* count;
  12. public:
  13.   SonyHandle(Sony* pp) : sp(pp), count(new int(1)){}
  14.   SonyHandle(const SonyHandle& sh):sp(sh.sp),count(sh.count){ (*count)++; }
  15.   Sony* operator->(){ return sp; }
  16.   SonyHandle& operator=(const SonyHandle& sh){
  17.     if(sh.sp == sp) return *this;  // 本来就指向同一个对象的情况
  18.     (*this).~SonyHandle();
  19.     sp = sh.sp;
  20.     count = sh.count;
  21.     (*count)++;
  22.     return *this;
  23.   }
  24.  ~SonyHandle(){
  25.     if(--(*count)==0){
  26.       delete sp;
  27.       delete count;
  28.     }
  29.   }
  30. };//-----------------------------------
  31. #endif  // HEADER_SONYHANDLE
  32.