问题描述
当我尝试使用自己的模板状态抱怨时编译失败:
src/fsm2.cpp:在成员函数‘boost::statechart::result SlewingST::react(EvTelLost)’中: src/fsm2.cpp:159:13: 错误:“discard_event”没有依赖模板参数的参数,因此“discard_event”声明必须可用
[-fpermissive] 返回丢弃事件(); ^~~~~~~~~~~~~ src/fsm2.cpp:159:13: 注意:(如果你使用‘-fpermissive’,G++ 会接受你的代码,但不推荐使用未声明的名称)
见下面我的小测试:
#include <iostream>
#include <ctime>
#include <boost/array.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/statechart/in_state_reaction.hpp>
#include <boost/statechart/deep_history.hpp>
using namespace std;
namespace sc = boost::statechart;
namespace mpl = boost::mpl;
// Which telescope are addressing
enum class Tel { TEL1 = 1,TEL2,TEL3,TEL4,TEL5,TEL6 };
// Searching event
struct EvSearching : sc::event< EvSearching > {};
// Parameterized event for telescope loss
//template< Tel aTel >
//struct EvTelLost : sc::event< EvTelLost< aTel > > {};
struct EvTelLost : sc::event< EvTelLost > {};
class IdleST;
class SearchingST;
template< Tel aTel> class SlewingST;
// class SlewingST;
class CFringeSearchSM : public sc::state_machine< CFringeSearchSM,IdleST >
{
public:
// Exposed facilities ------------------------------------------------------------
// ( Cons / Des) trutor
CFringeSearchSM() ;
~CFringeSearchSM() ;
int Init();
};
class IdleST : public sc::simple_state < IdleST,CFringeSearchSM>
{
public:
IdleST() ;
~IdleST() ;
// -------------------------------------------------------------------------------
typedef mpl::list< sc::custom_reaction< EvSearching > > reactions;
// Reaction to EvSearching
sc::result react( const EvSearching )
{
return transit<SearchingST>();
}
};
class SearchingST : public sc::simple_state < SearchingST,CFringeSearchSM,mpl::list< SlewingST<Tel::TEL1> > >
// mpl::list< SlewingST > >
{
public:
SearchingST() ;
~SearchingST () ;
};
template < Tel aTel >
class SlewingST :
public sc::simple_state < SlewingST<aTel>,SearchingST::orthogonal<int(aTel) - 1 > >
// public sc::simple_state < SlewingST,SearchingST::orthogonal < 0 > >
{
public:
// Exposed facilities ------------------------------------------------------------
// ( Cons / Des) trutor
SlewingST(){ ;}
~SlewingST(){ ;}
typedef mpl::list< sc::custom_reaction< EvTelLost > > reactions;
sc::result react( const EvTelLost )
{
return discard_event();
}
};
int main()
{
CFringeSearchSM myFringeSearchSM;
myFringeSearchSM.initiate();
return 0;
}
只要我更换模板类template class SlewingST;与类 SlewingST; ,一切顺利...
非常感谢您的提示!
西尔文
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)