Hello everyone,
About the release method implementation of smart pointer of COM, there are two approaches below, and approach 1 is preferred is recommended by Inside COM -- should be better.
Anyone know why approach 1 is better than approach 2?
(m_pI is interface pointer to a COM interface of type T, and it is a member variable of the COM smart pointer class)
Approach 1:
Code:
void Release()
{
if (m_pI != NULL)
{
T* pOld = m_pI;
m_pI = NULL;
pOld->Release();
}
}
Approach 2:
Code:
void Release()
{
if (m_pI != NULL)
{
m_pI -> Release();
m_pI = NULL;
}
}
thanks in advance,
George