#include <iostream>
class SuicideSample {
public:
SuicideSample() { std::cout << "ctor." << std::endl; }
~SuicideSample() { std::cout << "dtor." << std::endl; }
void DoIt( void ) {
delete this;
}
};
int main( int argc, char* argv[] )
{
SuicideSample* obj=new SuicideSample();
obj->DoIt();
// of course, object can kill itself, but if you try to kill it again
// program will crash.
//delete obj;
return 0;
}
沒有留言:
張貼留言