34 lines · c
1namespace std {2 3template <typename type>4class __shared_ptr {5protected:6 __shared_ptr();7 __shared_ptr(type *ptr);8 ~__shared_ptr();9public:10 type &operator*() { return *ptr; }11 type *operator->() { return ptr; }12 type *release();13 void reset();14 void reset(type *pt);15 16private:17 type *ptr;18};19 20template <typename type>21class shared_ptr : public __shared_ptr<type> {22public:23 shared_ptr();24 shared_ptr(type *ptr);25 shared_ptr(const shared_ptr<type> &t);26 shared_ptr(shared_ptr<type> &&t);27 ~shared_ptr();28 shared_ptr &operator=(shared_ptr &&);29 template <typename T>30 shared_ptr &operator=(shared_ptr<T> &&);31};32 33} // namespace std34