I believe there's a typo on this code snippet extracted from Stroustup's book, at its page 368 :
template <class X> class std::auto_ptr
{
template <class Y> struct auto_ptr_ref { /* ... */ }; // helper class
X * ptr;
public :
typedef X element_type;
explicit auto_ptr(X* p =0) throw() { ptr = 0; }
auto_ptr (auto_ptr& a) throw() { ptr = a.ptr; a.ptr = 0; } // note: not const auto_ptr&
/* ... */
};
Shouldn't
explicit auto_ptr(X* p =0) throw() { ptr = 0; }
be
explicit auto_ptr(X* p =0) throw() { ptr = p; }
instead ?
The errata for the book makes some changes: