Boost logo

Boost Users :

Subject: Re: [Boost-users] [Multi-Index] crash on iterator copy or assignment
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2009-03-13 11:11:30


On Thu, Mar 12, 2009 at 3:55 PM, JOAQUIN M. LOPEZ MUÑOZ <joaquin_at_[hidden]> wrote:

Hi Joaquín

>>     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) ... { ... }
  ...
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net