I'd like to have a class with member functions that return pointers to member functions.
That is, something like:
class Foo {
// typedef ????(Foo::* func)????
public:
Func s1();
Func s2();
Func s3();
}
Func Foo::s1() {
// do stuff
return &Foo::s2;
}
Func Foo::s2() {
// do stuff
return &Foo::s3;
}
Func Foo::s3() {
// do stuff
return 0;
}
Basically, what I try to do is to implement a state machine, where each state nows the next state and returns it by means of a function pointer.
Note: I'm not interested in other ways of implementing a state machine. I really like to know if it can be implemented in a way that looks like the above.
Context: I got inspired by this talk: http://www.youtube.com/watch?v=HxaD_trXwRE and wondered if a similar pattern can be used in C++.