首页 > 解决方案 > 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类;,一切顺利...

非常感谢您的提示!

西尔万

标签: c++templatesbooststatechart

解决方案


推荐阅读