Boost statechart fails to compile when using template state

30 Views Asked by At

compilation fails when I try to use my own template state complaining :

src/fsm2.cpp: In member function ‘boost::statechart::result SlewingST::react(EvTelLost)’: src/fsm2.cpp:159:13: error: there are no arguments to ‘discard_event’ that depend on a template parameter, so a declaration of ‘discard_event’ must be available

[-fpermissive] return discard_event(); ^~~~~~~~~~~~~ src/fsm2.cpp:159:13: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)

See below my tiny test :

#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;
}

As soon as I replace the template class template< Tel aTel> class SlewingST; with the class SlewingST; , all is going fine ...

Thanks a lot for your hints !

Sylvain

0

There are 0 best solutions below