|
Boost Users : |
Subject: Re: [Boost-users] How to make multi_index_container work withstd::unique_ptr?
From: Jayden Shui (jayden.shui_at_[hidden])
Date: 2011-12-20 18:41:06
On Tue, Dec 20, 2011 at 6:01 PM, Igor R <boost.lists_at_[hidden]> 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.
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