Tag: 自我毁灭

删除这个允许吗?

是否允许delete this; 如果delete语句是将在该类的该实例上执行的最后一个语句? 当然,我确定this指针代表的对象是new创建的。 我正在考虑这样的事情: 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: […]