Using the Boost status indicator, how can I go into a state unconditionally?

I have state A , which I would like to unconditionally move to the next state B after completion of constructor A Is it possible?

I tried to dispatch an event from a constructor that does not work, even if it compiles. Thanks.

Edit: Here is what I have 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 results in the following runtime statement failure:

 Assertion failed: get_pointer( pContext_ ) != 0, file /includ e/boost/statechart/simple_state.hpp, line 459 
+4
source share
1 answer

I updated my OP with my solution, this is how I can close the question.

The problem is that you cannot inherit from simple_state to achieve the desired transition, you must inherit from state , which requires you to modify the constructor accordingly.

 struct A : sc::state< A, Active > { public: typedef sc::custom_reaction< EventDoneA > reactions; A( my_context ctx ) : my_base( ctx ) { std::cout << "Inside of A()" << std::endl; post_event( EventDoneA() ); } sc::result react( const EventDoneA & ) { return transit< B >(); } }; 
+2
source

All Articles