smart_pointer example

#pragma once
template<typename T>
class smart_pointer
{
private:
  T* m_pRawPointer;
public:
  smart_pointer(T* pData) :m_pRawPointer(pData) {}

  //复制构造函数
  smart_pointer(const smart_pointer& anotherSP);

  //赋值
  smart_pointer& operator=(const smart_pointer& anotherSP);

  //
  T& operator* () const
  {
    return *(m_pRawPointer);
  }

  T* operator-> () const
  {
    return m_pRawPointer;
  }

};

 

posted @ 2019-06-08 20:16  西北逍遥  阅读(155)  评论(0编辑  收藏  举报