Smart Pointer

 

template <class T>
class SmartPtr
{
public:
  explicit SmartPtr(T* pointee) : pointee_(pointee);
  SmartPtr& operator=(const SmartPtr& other);
  ~SmartPtr();
  T& operator*() const
  {
   ...
   return *pointee_;
  }
  T* operator->() const
  {
   ...
   return pointee_;
  }
private:
  T* pointee_;
  ...
};

你可能感兴趣的:(Smart Pointer)