mardi 9 juin 2015

State Design Pattern - Don't want delete this pointer in member class

I am using the example below to implement a state design pattern.

http://ift.tt/1B2XdvI

I don't wanna delete the *this pointer inside a member class because is not safe (I will call other member function after delete).

void on(Machine *m)
{
    m->setCurrent(new ON());
    delete this;
}

Is there a better approach to implement the state design pattern? I thought about use Singletons, but I want avoid using singletons.

Best regards,

Aucun commentaire:

Enregistrer un commentaire