template // Object that holds a member function pointer, has a class state_of // conversion ctor and has operator() defined. { state_of (T::* member )( int ); // Remembering this member public: state_of( state_of (T::* m )( int ) ) : member( m ) {} state_of operator()( T *p, int e ) { return ( p->*member )( e ); } }; class state_machine { state_of current; state_of initial( int ); state_of other( int ); public: state_machine(); void operator()( int e ) { current = current( this, e ); } }; state_machine::state_machine() : current( initial ) {} state_of state_machine::initial( int event ) { switch( event ) { case 4: return other; default: break; } return current; } state_of state_machine::other( int event ) { return initial; } state_machine x; int main(int argc, char* argv[]) { x( 4 ); x( 2 ); x( 7 ); return 0; }