标签:const delete test auto_ptr 指针 private get class TE
template <class _Tp> class auto_ptr_test explicit auto_ptr_test(_Tp* __p = 0) : _M_ptr(__p) {}
auto_ptr_test(auto_ptr_test& __a) : _M_ptr(__a.release()) {}
auto_ptr_test& operator=(auto_ptr_test& __a)
{
if (&__a != this)
{
delete _M_ptr;
_M_ptr = __a.release();
}
return *this;
}
_Tp& operator*() const
{
return *_M_ptr;
}
_Tp* operator->() const
{
return _M_ptr;
}
_Tp* get() const
{
return _M_ptr;
}
_Tp* release()
{
_Tp* __tmp = _M_ptr;
_M_ptr = 0;
return __tmp;
}
~auto_ptr_test() { delete _M_ptr; }
};
标签:const delete test auto_ptr 指针 private get class TE
原文地址:http://blog.51cto.com/wenxuehui/2133761