
On 7/12/06, eric
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