在《COM原理与应用》里看到这样的代码:
ULONG CDictionary::Release()
{
m_Ref --;
if (m_Ref == 0 )
{
g_DictionaryNumber -- ;
delete this;
return 0;
}
return (ULONG) m_Ref;
}
在成员函数里delete this,把自己删了。
delete this会转化为:
this->~CDictionary();
operator delete(this);
虽然delete this之后对象已经坏了,但是马上返回,应该没问题。