Why does it need two forms? Thanks
explicit auto_ptr (T* ptr = 0) throw()
auto_ptr (auto_ptr& rhs) throw()
template<class Y>
auto_ptr (auto_ptr<Y>& rhs) throw()
auto_ptr& operator= (auto_ptr& rhs) throw()
template<class Y>
auto_ptr& operator= (auto_ptr<Y>& rhs) throw()
It has one copy constructor - the non-templated one.
The template constructor and assignment operator allow assignment of pointer types for which an implicit exists:
class A {}
class B : public A {}
B * b = new B();
A * a = b; // OK!
auto_ptr<B> b(new B);
auto_ptr<A> a = b; // *
without the template versions, (*) wouldn't work, as the compiler treats auto_ptr<A>
as a completely different type than auto_ptr<B>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With