RE: [Boost-Users] Is intrusive_ptr the thing to use?
-----Original Message----- From: Peter Dimov [mailto:pdimov@mmltd.net] Sent: Tuesday, November 26, 2002 6:49 AM To: Boost-Users@yahoogroups.com Subject: Re: [Boost-Users] Is intrusive_ptr the thing to use?
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. -Greg
From: "Hickman, Greg"
From: Peter Dimov [mailto:pdimov@mmltd.net] 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.
participants (2)
-
Hickman, Greg
-
Peter Dimov