0
ブーストステートチャートを使用して簡単なステートマシンを実装しようとしています。 私はこのステートマシンにいくつかのバリエーションがあるので、テンプレートにラップしてステートマシンをテンプレートパラメータとして渡すことをお勧めします。ブーストステートチャート - ステートチャートをテンプレートパラメータとして使用するときのコンパイルエラー
ただし、コンパイルエラーが発生しています。
コード:
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/transition.hpp>
namespace sc = boost::statechart;
class ComponentType
{
};
class FSM {
protected:
struct stInit ;
public:
struct Machine : sc::state_machine< Machine, stInit > {};
protected:
struct stInit : ComponentType, sc::simple_state< stInit, Machine > {};
};
template <class fsm>
void run() {
typename fsm::Machine m_fsm;
const ComponentType &t = m_fsm.state_cast<const ComponentType &>();
(void) t;
}
int main() {
run<FSM>();
}
コンパイルエラー:しかし
fsmtest.cpp: In function ‘void run()’:
fsmtest.cpp:33:45: error: expected primary-expression before ‘const’
const ComponentType &t = m_fsm.state_cast<const ComponentType &>();
^
fsmtest.cpp:33:45: error: expected ‘,’ or ‘;’ before ‘const’
、テンプレートの代わりにtypedefを使用している場合:
typedef FSM fsm;
//template <class fsm>
と
run();
// run<FSM>();
すべてがエラーなくコンパイルされます。
私には何が欠けていますか?
(コンパイラ:G ++ 4.8.4、OS:Ubuntuの14.04、ブースト:1.54)
これでコンパイルされます。ありがとう! – oferlivny