Can I write delete this;
when I delete an instance of the class I created with new at the end?
Write it like this.
void doStuff()
{
// This object is a working module
// When you want to switch to another module,
controller->setWorkingModule(new OtherModule());
// The other module calculates it
// Organize this
delete this;
}
Or can I make otherClass
kill this instead?
void doStuff()
{
otherClass.deleteMe(this); // void deleteMe(void *obj) { delete obj; }
}
delete this;
Writing together is called suicide
The suicide of the object should be written with caution, but to summarize the contents of The C++ FAQ Lite simply,
You should only write if you are 100% sure of something.
© 2024 OneMinuteCode. All rights reserved.