Search code examples
c++state-machineboost-statechart

In Boost.Statechart, what's the difference between state and simple_state?


In implementing a state machine using Boost.Statechart, I came across a problem arising from attempting to access the outer context of a simple_state from its constructor. A comment in simple_state.hpp tells me:

    // This assert fails when an attempt is made to access an outer 
    // context from a constructor of a state that is *not* a subtype of
    // state<>. To correct this, derive from state<> instead of
    // simple_state<>.

Apart from apparently being able to access the outer context from its constructor, what differences or implications are there in using state<> instead of simple_state<> as the base class for my states?


Solution

  • There are a number of other things that you can do from a state<> derived constructor that you cannot do from a simple_state<> derived constructor. There are a list in the documentation for the state class. I found posting events to be the big benefit of deriving from state<>.

    It's been a while since I used it, but I don't remember there being any implications, other than you having to implement the forwarding constructor for each class derived from state (stated in docs), as state<> is derived from simple_state<>.