最佳答案
如果delete语句是将在该类实例上执行的最后一条语句,是否允许delete this;
?当然,我确信由__abc1 -指针表示的对象是new
ly-created的。
我在想这样的事情:
void SomeModule::doStuff()
{
// in the controller, "this" object of SomeModule is the "current module"
// now, if I want to switch over to a new Module, eg:
controller->setWorkingModule(new OtherModule());
// since the new "OtherModule" object will take the lead,
// I want to get rid of this "SomeModule" object:
delete this;
}
我能这样做吗?