I've took a look into atlbase.h
to see how CComPtr<>
is implemented, and stumbled upon Release()
function in base class CComPtrBase<>
which releases the underlaying object like this:
// Release the interface and set to NULL
void Release() throw()
{
T* pTemp = p;
if (pTemp)
{
p = NULL;
pTemp->Release();
}
}
My intelect is not good enough to see what's the point of this temporary pointer pTemp
?
Why this code isn't just:
void Release() throw()
{
if (p)
{
p->Release();
// EDIT:
p = NULL;
}
}
Now if you take a look at destructor, the destructor is defined just like my expectation from above sample, what is the difference?