#pragma
once
template < class type >
class auto_ptr_test
{
public:
auto_ptr_test( type * p = 0):p_(p){}
~auto_ptr_test(void){delete p_;}
auto_ptr_test(const auto_ptr_test & auto_ptr)
{
p_ = auto_ptr.release();
}
type & operator = (const auto_ptr_test & auto_ptr)
{
if(&auto_ptr != this) //防止自我复制
{
delete p_;
p_ = auto_ptr.release() ;
}
return *this;
}
type * release()
{
type * temp = p_;
p_=0;
return temp;
}
type& operator * ()
{
return *p_;
}
type * operator -> ()
{
return p_;
}
private:
type *p_;
} ;
template < class type >
class auto_ptr_test
{
public:
auto_ptr_test( type * p = 0):p_(p){}
~auto_ptr_test(void){delete p_;}
auto_ptr_test(const auto_ptr_test & auto_ptr)
{
p_ = auto_ptr.release();
}
type & operator = (const auto_ptr_test & auto_ptr)
{
if(&auto_ptr != this) //防止自我复制
{
delete p_;
p_ = auto_ptr.release() ;
}
return *this;
}
type * release()
{
type * temp = p_;
p_=0;
return temp;
}
type& operator * ()
{
return *p_;
}
type * operator -> ()
{
return p_;
}
private:
type *p_;
} ;