samedi 27 février 2016

Function Type which Returns Itself

I'm trying to write a very minimal state machine in C++. I'd like the states to be methods of the machine's class, and each state, when run, should return the new state to move to. Naturally, I'm using a few typedef's to help out.

template <typename C, typename E>
using State = State<C, E> (C::*)(Stream<E>&);

A state should be a member function (in class C) which takes a stream object and yields a new state. I'm getting the following error.

fsm.hpp:8:15: error: ‘State’ does not name a type
 using State = State<C, E> (C::*)(Stream<E>&);

Obviously, State is not declared yet on the line that should declare State. As far as I know, there's no way to "forward declare" a typedef, so what is the appropriate way to declare this typename?

Aucun commentaire:

Enregistrer un commentaire