|
Re: Is intrusive_ptr the thing to use?: msg#00283lib.boost.user
I had this question a few weeks ago and there wasn't really a solution so I wrote my own set of classes derived from shared_ptr. http://systematicattack.net/smart_ptr.h I'm using this in a fairly large project right now and I think everything is working properly. I have also included a class called observer which is derived from weak_ptr. Here is an example of it's usage The only problem with it currently is that the smart_class MUST be managed with smart_ptrs, if you try to 'delete' it, it will try to delete itself and crash. Also, you cannot instantiate a smart_class on the stack, same problem.. There might be a way to get around this, but it isn't a priority for me yet. I hope this is of some help. --Stephen class MyObject : public smart_class<MyObject> { void something(); } MyObject::something() { blah = new Whatever(); blah->member = this; // this works } main() { MyObject *mo = new MyObject; smart_ptr<MyObject> sp(mo); // or sp = mo; observer<MyObject> o = sp; // or o = sp; o = mo; } On Mon, Nov 25, 2002 at 03:01:28PM -0600, Hickman, Greg wrote: > I need an object managed through a shared_ptr to be able to pass itself > (i.e., this) to another object which also expects a shared_ptr. Is there a > preferred implementation technique for this when using the boost smart > pointers? > > I think I've seen conversation in the past about deriving from > boost::counted_base and calling shared_from_this(), but I think I also > remember seeing comments to the effect that this is going away. OTOH, I > know there's something called intrusive_ptr that's currently undocumented. > > Should I be using one of these approaches? If the answer is intrusive_ptr, > are there docs? Should I roll my own? What's a Booster to do? > > -Greg 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: | Lambda questions: 00283, Claus Rasmussen |
|---|---|
| Next by Date: | RE: Is intrusive_ptr the thing to use?: 00283, Mark Storer |
| Previous by Thread: | Is intrusive_ptr the thing to use?i: 00283, Hickman, Greg |
| Next by Thread: | Re: Is intrusive_ptr the thing to use?: 00283, Peter Dimov |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |