微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用模板状态时,Boost 状态图无法编译

如何解决使用模板状态时,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 class SlewingST;与类 SlewingST; ,一切顺利...

非常感谢您的提示

西尔文

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。