Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-19 18:00:28


"Bronek Kozicki" <brok_at_[hidden]> wrote in message
news:01f501c3dedd$02960270$d801a8c0_at_waw.home...
> Jonathan Turkanis <technews_at_[hidden]> wrote:
> > The above example is okay, but I'm pretty sure your general claim
is
> > too strong. Consider:
> >
> > Base* new_base() { return new Derived; }
> >
> > auto_ptr<Base> p(new_base());
> >
> > How can the auto_ptr constructor know that Derived is the most
derived
> > type of the pointer? Even at construction, it does not have enough
> > information to free the pointer properly.
>
>
> That's true. "Base *" is to blame, and I see no way to pass type
> information to auto_ptr (or maybe move_ptr ;) constructor. I called
it
> "pathological case". Conclusion is that raw pointer should be
directly
> packed into smart pointer, and I think that's not new.
>

I'm sorry if you mentioned this possibility and I overlooked it. I
think the proper conclusion is the usual one: if you use a
pointer-to-derived as a pointer-to-base, you can't expect correct
deletion unless you have a virtual destructor. Do you disagree? I'm
not suggesting any change to your code, just to your description of
it.

Jonathan


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