consider that in your example, I can legally write a free function
void foo()
{
FSM::submachine sub;
sub.onentry();
}
where there is no FSM instance that sub
could refer to.
Either, as Oli says, have the submachine
object store a reference to its parent FSM
object, or perhaps just pass the value of x
directly into onentry
(it isn't clear how it gets invoked).
From a quick look at the Boost.MSM docs I found this note on non-default-constructed submachines.
It's pretty ugly, I don't understand the backend enough to paraphrase it here, and the literal code won't make enough sense in isolation to be worth pasting.
The example code linked from there also shows the submachine's entry method with the following signature:
template <class Event,class FSM> void on_entry(Event const&,FSM& );
if that's accurate, you can either store a pointer to your outer state machine on_entry
, or extract the value of x there and record it in the submachine.