On Thu, Mar 12, 2009 at 3:55 PM, JOAQUIN M. LOPEZ MUÑOZ
std::auto_ptr<ByTypeFooIterator> iter_ptr = new ByTypeFooIterator; FWIW, the last line should not compile, and the fact that it does in VS2005 is a compiler bug:
This is getting to be off topic, but I don't really understand why the line above is a bug in fact. I'm not C++ expert for sure, but so far I've assumed that writing "type var = rhs;" was equivalent to "type var(rhs);" and was not really an assignment but a construction in disguise. I'm surprised that the compiler would prefer the non-explicit Ctor taking the ref, which implies an implicit builtin conversion of ByTypeFooIterator* to void* and a non-builtin implicit conversion of the void* to auto_ptr_ref, to the explicit auto_ptr Ctor that perfectly matches the signature of the arg to the declared auto_ptr. Does using the explicit keyword precludes the "type var = rhs;" <==> "type var(rhs);" equivalence that I've assimilated (incorrectly?) into my mental model of C++? If someone could shed some light on this for me, I'd appreciate, so I can avoid repeating this mistake and possibly correct my understanding of these "initialization assignments". Thanks, --DD template<class _Ty> class auto_ptr { ... explicit auto_ptr(_Ty *_Ptr = 0) ... { ... } auto_ptr(auto_ptr_ref<_Ty> _Right) ... { ... } ... };