Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-04-24 11:53:30


From: "Fernando Cacciola" <fcacciola_at_[hidden]>
> "Peter Dimov" <pdimov_at_[hidden]> wrote in message
> news:000501c1eb7a$0f4a2760$1d00a8c0_at_pdimov2...
> > I've changed the shared_ptr(T *) constructor to a member template,
> > template<class Y> shared_ptr(Y *).
> >
> I've just looked at it.
>
> Why is the cast from Y* to T* implicit?

I'm not sure I understand the question. What other kind of cast is
applicable? If you write

T * p = new Y;

there must exist a conversion from Y* to T*, right?

shared_ptr<T> p(new Y);

is similar.

> AFAIK this could go wrong when complex polymorphism is involved:
>
> shared_ptr<Base> pb( new Derived ) ;

How could this go wrong?

> My own smart ptr has both template and non template ctors.
> The template ctor uses boost::polymorphic_cast.

And doesn't work for non-polymorphic types; this may be considered a
feature, of course.

> > This breaks some existing code since '0' is no longer an acceptable
> > argument; for instance, px.reset(0) needs to be rewritten as px.reset().
> >
> I think this could be resolved by having both template and non-template
> versions.

I don't want to resolve it. ;-) The new behavior is better.


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