Boost logo

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 17:38:53


On Tue, Dec 20, 2011 at 5:23 PM, Igor R <boost.lists_at_[hidden]> wrote:

> Please don't top-post.
>
> > My case is like that: I have a number of polymorphic objects which can be
> > used or referenced by other objects. I put them (the polymorphic
> objects) in
> > MIC. And if one changes its type (not only its value), its users know it
> > automatically by shared_ptr. I think I need MIC with shared_ptr pointing
> to
> > scoped_ptr. Am I right? Or is there other way to easy handle it?
>
> How can an object change its type?! In c++ type is a compile-type
> attribute.
> Perhaps you mean that you erase an object from the container and add
> another one, or replace some object. In any case, shared_ptr would be
> fine.
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

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.

Any good way? 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