D
dr.oktopus
Hello,
I am moving my first steps into the wonderful world of oop.
I have considered this approach in writing a fsm.
class fsm {
public:
void run_fsm (void); // advance machine for 1 step
private:
void (*state) (void);
void state1 (void);
void state2 (void);
..
};
void fsm::run_fsm (void)
{
state();
}
void fsm::state1 (void)
{
..
if (statehastochangetostate2)
state = state2;
..
}
void fsm::state2 (void)
{
..
if (statehastochangetostate1)
state = state1;
..
}
It is a simple fsm, but what I would like to know
are your opinions about this approach.
I don't try to compile it (I don't have a compiler at hand),
but I think it should work.
Suggestions?
Thanks,
willy
I am moving my first steps into the wonderful world of oop.
I have considered this approach in writing a fsm.
class fsm {
public:
void run_fsm (void); // advance machine for 1 step
private:
void (*state) (void);
void state1 (void);
void state2 (void);
..
};
void fsm::run_fsm (void)
{
state();
}
void fsm::state1 (void)
{
..
if (statehastochangetostate2)
state = state2;
..
}
void fsm::state2 (void)
{
..
if (statehastochangetostate1)
state = state1;
..
}
It is a simple fsm, but what I would like to know
are your opinions about this approach.
I don't try to compile it (I don't have a compiler at hand),
but I think it should work.
Suggestions?
Thanks,
willy