This question already has an answer here:
- C++: Delete this? 9 answers
I am using the example below to implement a state design pattern.
I am concerned about delete a this pointer inside a member class:
void on(Machine *m)
{
m->setCurrent(new ON());
delete this;
}
Is it safe to do that? What could happens if I call other member function after delete?
Is there a better approach?
Best regards,
Aucun commentaire:
Enregistrer un commentaire