From: Kovalenko D. <dmi...@gm...> - 2011-03-30 11:15:35
|
> Ok, here is a code: > > Interface* a = new RefCountedClass; > Interface* b = NULL; > b = a; > delete a; > b->Anything(); > > I don't understand how reference counting works here. Could you explain? InterfacePtr a(new RefCountedClass()); //cntRef==1 InterfacePtr b; a=b; //cntRef==2 a.Release(); //or a=NULL; //cntRef==1 b->Anything(); b.Release(); //last release b.Release(); //no problem --- When you work with RefCountedClass, you must forget about "operator delete" In good C++ code, you do not make a explicit call of AddRef/Release. This is work for smart-pointer Regards, Kovalenko Dmitry |