8 Jan
2006
8 Jan
'06
11 a.m.
Serge Skorokhodov wrote:
Pooyan McSporran wrote:
void test (MemoryPtr m) { m -> remember1 (FooPtr (this));
Definetely a misuse. A poiner to a "newed" object or another shared_ptr must be passed to share_ptr ctor. Actually, you are baypassing reference counting here. "this" is neither:( Try this:
void test ( MemoryPtr m, FooPtr f ) { m->remember1( f ); }
Or alternatively, you could use enable_shared_from_this (which is the "standard" way to construct a shared_ptr from a "this" pointer).