Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2002-06-24 05:07:00


Peter Dimov wrote:
>
> From: "Markus Schöpflin" <markus.schoepflin_at_[hidden]>

...

> > Ok, thanks for the clarification. Is there anywhere some design
> > rationale besides the FAQ where I can look up what should work
> > and what not and why it works the way it does?
>
> First let me clarify that this is not a problem with MSVC 6. 'Y *' can not
> be deduced from '0'.

Oops, now that you point it out it's kind of obvious.

>
> No, there is no rationale document yet. Sorry.

No need to apologize. I very much appreciate your work. I just
hoped there is something that would keep me from asking silly
questions or posting fixes to things that ain't broken. :-)

>
> The reason that the zero initialization doesn't work (1.28+) is that the two
> constructors are subtly different; ...
>
> > For me this behaviour is kind of surprising as auto_ptr does
> > have such a constructor.
>
> ... in the auto_ptr/scoped_ptr case, the default constructor _is_
> zero-initialization. shared_ptr's default constructor, however, does not
> require a complete type, and does not invoke 'delete' on destruction. The
> constructor that takes a raw pointer does require a complete type for the
> pointed-to object, and does invoke 'delete p' on destruction, where 'p' is
> the value passed to the constructor, complete with its original type.
>
> So if you say
>
> shared_ptr<void> px(static_cast<X*>(0));
>
> when 'px' is destructed, it will invoke
>
> delete static_cast<X*>(0);
>
> I could have made the simple case
>
> shared_ptr<int> px(0);
>
> work, but it's better not to; it is important to understand the difference.
> And of course,
>
> shared_ptr<void> px(0);
>
> won't work anyway, since void is incomplete.
>

Do I understand you correctly? I can use a shared_ptr<void> as some kind
of really smart pointer which will handle any type I happen to stuff
into it?

Markus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk