|
RE: Is intrusive_ptr the thing to use?: msg#00304lib.boost.user
From: Peter Dimov [mailto:pdimov@xxxxxxxxx] > From: "Hickman, Greg" <greg.hickman@xxxxxxxx> > > > From: Peter Dimov [mailto:pdimov@xxxxxxxxx] > > > If 'f' is virtual, have the object store a weak_ptr to itself: > > > > > > class X > > > { > > > private: > > > > > > weak_ptr<X> weak_this; > > > > > > X(); > > > X(X const &); > > > X& operator=(X const &); > > > > > > public: > > > > > > static shared_ptr<X> create() > > > { > > > shared_ptr<X> px(new X); > > > px->weak_this = px; > > > return px; > > > } > > > > I must be missing something here, because it appears as though you > > can't derive a Y from X and still initialize X::weak_this. > > You could simply make X::weak_this and X::X() protected... > although if you follow the design rule that says that > non-leaf classes should be abstract (and if possible contain > no data) this shouldn't be necessary, as X as pictured above > would be a leaf. Its seems the leaf itself must implement the factory method/weak_this idiom. This initially didn't seem like a good idea in our case since clients write the leaves - we only provide X. But on second thought, perhaps two alternatives are (1) provide a helper template for clients to use when deriving from X to automatically declare the static create()/weak_this pair, or (2) use an intrusive reference counting approach for X. If an intrusive approach ultimately works better for us, what should I do as a boost 1.29.0 user: use counted_base/shared_from_this, or intrusive_ptr (which I admittedly haven't even looked at)? Any suggestions you have are more than welcome. -Greg ------------------------ Yahoo! Groups Sponsor ---------------------~--> Get 128 Bit SSL Encryption! http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/EbFolB/TM ---------------------------------------------------------------------~-> Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@xxxxxxxxxxxxxxx> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Lambda questions: 00304, Jaakko Jarvi |
|---|---|
| Next by Date: | Re: Lambda questions: 00304, Claus Rasmussen |
| Previous by Thread: | Re: Is intrusive_ptr the thing to use?i: 00304, Peter Dimov |
| Next by Thread: | Re: Is intrusive_ptr the thing to use?: 00304, Peter Dimov |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |