#ifndef HANDLE_H#define HANDLE_H #include "Animal.h"templateclass Handle{ public: Handle(T *ptr); Handle(const Handle &other); Handle &operator = (const Handle &other); ~Handle(); T *operator->(); private: T *ptr_;};template inline Handle ::Handle(T *ptr) :ptr_(ptr->copy()){}template inline Handle ::Handle(const Handle &other) :ptr_(other.ptr_->copy()){}template inline Handle &Handle ::operator = (const Handle &other){ if(this != &other){ delete ptr_; ptr_ = other.ptr_->copy(); } return *this;}template inline Handle ::~Handle(){ delete ptr_;}template inline T *Handle ::operator -> (){ return ptr_;}#endif /*HANDLE_H*/
版权声明:本文博主原创文章,博客,未经同意不得转载。