From: Ken Shaw (ken_at_[hidden])
Date: 2002-04-08 12:08:18
----- Original Message -----
From: "James Kanze" <kanze_at_[hidden]>
Sent: Sunday, April 07, 2002 3:04 PM
Subject: Re: [boost] plain pointers and shared_ptr
> "Ken Shaw" <ken_at_[hidden]> writes:
> |> An even easier solution is to simply use shared_ptr<> everywhere
> |> without exception, it is as thread safe as any code is likely to get
> |> at present.
> This is, of course, the correct solution. Still, I've been unable to
> make it work. What do I have to do so that "this" is a shared_ptr<>?
Allocate the object on the stack with new as follows:
shared_ptr<Foo> fooptr(new Foo());
If you are talking about returning a this pointer from a member function to
the outside world this is really not such a good idea. Instead I suggest you
change your return type to be reference to the object, this is how the STL
handles such cases and memory allocation and object lifetime issues only
come up in multithreaded applications and I have still not found a good real
world way to handle this.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk