Udostępnij za pośrednictwem


Riffing on Raymond - incrementing the reference count on a smart pointer

This blog post has moved to https://matthewvaneerde.wordpress.com/2015/10/27/riffing-on-raymond-incrementing-the-reference-count-on-a-smart-pointer/

Comments

  • Anonymous
    October 28, 2015
    The comment has been removed

  • Anonymous
    October 28, 2015
    I agree that in most cases using .Detach() is appropriate. But what if you want to continue to use the object after the consuming function returns? GetThingy(&sp); UseThingyEatsInput(sp.Detach()); UseThingy(sp); // gets nullptr! I suppose the .Detach() solution can still be used with a temporary: UseThingyEatsInput(SmartPointerType(p).Detach()); Effectively this becomes a .GetAddRefdPointer().

  • Anonymous
    October 28, 2015
    Well, uhm... if you want to continue to use the object, then don't throw it away before you're done with it. In other words, call CoUnmarshalInterface instead of CoGetInterfaceAndReleaseStream (Raymond's suggestion 2).

  • Anonymous
    October 29, 2015
    The comment has been removed