private:
T *_ptr;
};
+
+ template<class T>
+ class AutoCPtr
+ {
+ public:
+ AutoCPtr(T *ptr=0):_ptr(ptr) { }
+ ~AutoCPtr() { destroyPtr(); }
+ AutoCPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; }
+ T *operator->() { return _ptr ; }
+ const T *operator->() const { return _ptr; }
+ T& operator*() { return *_ptr; }
+ const T& operator*() const { return *_ptr; }
+ operator T *() { return _ptr; }
+ operator const T *() const { return _ptr; }
+ private:
+ void destroyPtr() { free(_ptr); }
+ private:
+ T *_ptr;
+ };
}
#endif