Boost logo

Boost :

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

"Bronek Kozicki" <brok_at_[hidden]> wrote in message
> Jonathan Turkanis <technews_at_[hidden]> wrote:
> > The above example is okay, but I'm pretty sure your general claim
> > 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
> > 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
> "pathological case". Conclusion is that raw pointer should be
> 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


Boost list run by bdawes at, gregod at, cpdaniel at, john at