Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-01-19 17:25:56


"Bronek Kozicki" <brok_at_[hidden]> wrote in message
news:006f01c3ddfc$9f3e6770$d801a8c0_at_waw.home...
> Jonathan Turkanis <technews_at_[hidden]> wrote:

>
> * you no longer need to make your class polymorphic in order to call
> right destructor at the point of auto_ptr destuction, like in
following
> example:
> struct Base{};
> struct Derived : public Base {};
> auto_ptr<Base> p = auto_ptr<Base> (new Derived);
> // which destructor gets called when p goes out of scope ?
>

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.

I verified this on VC7.1.

Regards,

Jonathan


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