Boost logo

Boost Users :

Subject: Re: [Boost-users] shared_ptr and global reset
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2009-02-26 07:06:52


Igor R wrote:
> Let's say that I have many shared_ptr<A> sharing ownership to the
> same A object. At some point, I would like all those shared_ptr to
> point to a new Object A. Is there an easy (and safe) way to
> accomplish that?
> I know how to do that for one shared_ptr using either "reset",
> either operator = but in order to do this for all shared_ptr
> sharing ownership, the only way I could think of is through a
> registration mechanism (like the Observer pattern) but this sounds
> an overkilling process to me.
>
>
> You can wrap ObjectA by a proxy object, so that all the shared_ptr's
> point to that proxy that holds actual object. Then you can "reset" the
> object in the proxy.

Wouldn't shared_ptr itself serve as the proxy:

        shared_ptr< shared_ptr<A> > aPtrPtr;

Jeff


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