Here is a simplified version of the code I'm trying to write:
template<typename Derived>
class StateMachine
{
public:
void SetState(Derived::State s) {
static_cast<Derived*>(this)->TransitionTo(s);
}
};
class MyFSM : public StateMachine<MyFSM>
{
public:
enum class State {
State1,
State2,
State3
};
void TransitionTo(State s) {
_state = s;
}
private:
State _state = State::State1;
};
I am using C ++ 11 with clang. Error I get here 10:17: error: missing 'typename' prior to dependent type name 'Derived::State'
for the announcement SetState
. I also tried adding typename Derived::State DerivedState;
and then using DerivedState
instead Derived::State
, but then I get error: unknown type name 'DerivedState'
.
Even more confusing, I tried it typedef typename Derived::State DerivedState;
, and then received an error: error: no type named 'State' in 'MyFSM'
. My last attempt was typedef enum class Derived::State DerivedState;
, and then I get very tangled issue for all: error: no enum named 'State' in 'MyFSM'
.
! , . , , , StateMachine
, , . , this
SetState
( MyFSM
, , ), . , , - , .