Using Boost statechart, how can I transition to a state unconditionally?

Posted by nickb on Stack Overflow See other posts from Stack Overflow or by nickb
Published on 2011-10-12T18:03:45Z Indexed on 2011/11/15 1:50 UTC
Read the original article Hit count: 183

Filed under:
|
|

I have a state A that I would like to transition to its next state B unconditionally, once the constructor of A has completed. Is this possible?

I tried posting an event from the constructor, which does not work, even though it compiles. Thanks.

Edit: Here is what I've tried so far:

struct A : sc::simple_state< A, Active >
{
    public:
        typedef sc::custom_reaction< EventDoneA > reactions;
        A()
        {
            std::cout << "Inside of A()" << std::endl;
            post_event( EventDoneA() );
        }

        sc::result react( const EventDoneA & )
        {
            return transit< B >();
        }
};

This yields the following runtime assertion failure:

Assertion failed: get_pointer( pContext_ ) != 0, file /includ
e/boost/statechart/simple_state.hpp, line 459

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost