Object-Oriented Suicide or delete this;
问题 The following code compiled with MSVC9.0 runs and outputs Destructor four times, which is logical. #include <iostream> class SomeClass { public: void CommitSuicide() { delete this; } void Reincarnate() { this->~SomeClass(); new (this) SomeClass; } ~SomeClass() { std::cout << "Destructor\n"; } }; int main() { SomeClass* p = new SomeClass; p->CommitSuicide(); p = new SomeClass; p->Reincarnate(); p->~SomeClass(); //line 5 p->CommitSuicide(); } I think the first 4 lines of code in main do not