0

I'm using Boost Statechart Event for a State-Machine. I'm thinking of a vector/list to hold events.

I tried the following -

template <typename T>
struct Event : public boost::statechart::event<Event>
{
    Event(const T & event) : m_event(event)
    {
        //
    }
    ~Event()
    {
    }
    Event & getEvent() const { return m_event; }
    Event m_event;
};

struct EventOne : public Event<EventOne> {};
struct EventTwo : public Event<EventTwo> {};

In State-Machine class I want to add every event to a vector/list, which I'm unable to.

class StateOne;
class StateMachine : public boost::statechart::state_machine<StateMachine, StateOne>
{
    StateMachine() = default;
    ~StateMachine() = default;
private:    
    std::list<boost::statechart::event<Event>> events; // Error in formation of std::list here
};

My objective is to add events to the list as mentioned below -

EventOne eOne;
EventTwo eTwo;

events.push_back(eOne);
events.push_back(eTwo);
events.push_back(EventOne());

I'm missing something. Kindly help me with the formation of vector/list with the example code. Thanks.

Errors:

error C3203: 'Event': unspecialized class template can't be used as a template argument for template parameter 'MostDerived', expected a real type
error C2460: 'Event<EventOne>::m_event': uses 'Event<Startup>', which is being defined
error C3203: 'Event': unspecialized class template can't be used as a template argument for template parameter 'MostDerived', expected a real type
r18ul
  • 1,082
  • 2
  • 12
  • 30
  • Well, you can't have a list holding different types. – Matthieu Brucher Dec 31 '18 at 11:22
  • They don't belong to different types. All the events are derived from a base class that corresponds to a single type boost::statechart::event. Isn't it so? – r18ul Dec 31 '18 at 11:28
  • It would be useful to add the actual error statement in the post. – P.W Dec 31 '18 at 11:32
  • Yes, but `Event` is a template class, you need to specify which type you want to store. If you want to store pointers to them, then yes, it works if you store `boost::statechart::event*`. – Matthieu Brucher Dec 31 '18 at 11:32
  • Added errors more clarity. Kindly help. – r18ul Dec 31 '18 at 11:39
  • You should follow the Boost Statechart tutorial's way of doing this: https://www.boost.org/doc/libs/1_69_0/libs/statechart/doc/tutorial.html – Eljay Dec 31 '18 at 11:49

0 Answers0