On Tue, Dec 20, 2011 at 6:01 PM, Igor R <boost.lists@gmail.com> wrote:
> What I mean is dynamic changing. For example
>
> class B {public: virtual ~B()}  // Base class.
> class D1 : public B {}            // D1 derived from B
> class D2 : public B {}            // D1 derived from B
>
> scoped_ptr<B> p = new D1;   // pointing to D1
> p.reset(new D2);    // change pointing to D2
>
> If they are shared between owners and users, I need type
>
>        shared_ptr<scoped_ptr<B>>
>
> But this type make my code hard to develop and also read.

And what's wrong with just shared_ptr<B>? Why do you need the
additional level of indirection?

For example

int main()
{
    shared_ptr<B> p(new D1);
    shared_ptr<B> user1 = p;  // User1 uses p
    p.reset(new D2); // p changes pointed type to D2, user1 still points to D1
    return 0;
}
 

or 

int main()
{
    shared_ptr<B> p(new D1);
    shared_ptr<B>* user2 = &p;  // User2 uses p, but the p.use_count() is still 1.
    p.reset(new D2); // p changes pointed  type to D2, *user2 points to D1
    return 0;
}

Thanks.