c++ - Boost 状态图在使用模板状态时无法编译
问题描述
当我尝试使用自己的模板状态抱怨时编译失败:
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< Tel aTel> class SlewingST; 与SlewingST类;,一切顺利...
非常感谢您的提示!
西尔万
解决方案
推荐阅读
- javascript - 如何创建一个可以连接到 React 中的数组的对象?
- python - 如何解释 ML 训练输出
- r - 按组回归
- macros - 如何使用语法检查变量的度量(名义/序数/比例)?
- java - Java Mapper 接口我如何注入控制多个 DBMS
- java - 当查询结果为空时,如何使调用返回空字符串而不是 NULL 的 SQL 查询的方法?
- c++ - Why dοes this code output 1?
- algorithm - 两个字符串之间公共最长子串的递归解决方案
- theory - Fibers / Coroutines vs Delimited Continuations
- python-3.x - BeautifulSoup ... AttributeError:“NoneType”对象没有属性“文本”