Boost logo

Boost :

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

"Bronek Kozicki" <brok_at_[hidden]> wrote in message
> 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
> 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.



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