OK thanks, I'm familiar with release(), but I never saw a detach() before.
I can certainly see the danger of having a release() or detach() function in a shared_ptr.
Printable View
O_o
Does 'CComPtr::Detach' alter the reference? Or does it just return the pointer and null the member for that particular instance of 'CComPtr'?
Can you give more information about this "certain circumstance"?
Soma
That's why CComPtr::Detach does. I can't remember more details right now. It's just from the documentation.Quote:
Releases ownership of a pointer, sets the CComPtrBase::p data member variable to NULL, and returns a copy of the pointer.
But it should guarantee that it returns the pointer and does not Release it beforehand (which shared_ptr would do).
CComPtr has the advantage that the reference counting of COM objects is internal and publicly documented. If a shared_ptr gives up its pointer, it has to decrement the refcount, because there's no way for the user to do it.