How could a member method delete the object?
I am currently studying COM and the following code confused me. STDMETHODIMP _(ULONG) ComCar::Release() { if(--m_refCount==0) delete this; // how could this "suicide" deletion be possible? return m_refCount; } I am wondering how could it be possible to delete an object instance within its member method? So I made the following experiment: class A { public: void Suicide(void); void Echo(void); char name; }; void A::Echo(void) { ::printf("echo = %c\n",name); } void A::Suicide(void) { delete this; } int main(void) { A a; a.name='a'; a.Suicide(); //failed } And the execution does failed at a