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 FSM fsm;
//template <class fsm>
및
run();
// run<FSM>();
모든 것이 오류없이 컴파일됩니다.
무엇이 누락 되었습니까?
(: OS g ++ 4.8.4 : 컴파일러 우분투 14.04, 부스트 : 1.54)
이제 컴파일됩니다. 감사! – oferlivny