|
Boost Users : |
From: me22 (me22.ca_at_[hidden])
Date: 2006-07-12 10:16:26
On 7/12/06, eric <spamsink42_at_[hidden]> wrote:
> in other words, when you assign a value to a shared_ptr, does it make
> any difference what class you specify for that value, as long as the
> class of the underlying object can be dynamically cast to the class
> that was used to declare the shared_ptr?
>
In the example you gave, there's no difference in effect.
The important difference is in the default deleter. shared_ptr<Foo>'s
default deleter will call delete on a Foo* while shared_ptr<Bar>'s
default deleter will call it on a Bar*. Since your base class's
destructor is virtual, it doesn't make any difference in the example.
If your destructor were non-virtual, then you'd have to use
shared_ptr<Bar>(new Bar) to get the correct destructors called. (But
without any virtual functions, the dynamic casting wouldn't compile.)
~ Scott McMurray
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net