I have a state machine look like this:
class FsmDef : public boost::msm::front::state_machine_def<FsmDef> {
private:
Args args;
using State = boost::msm::front::state<>;
public:
FsmDef(Args args) : args{args}
{}
struct InitState {};
struct State1 {
Args1 args1;
State1(Args1 args1) : args1(args1)
{}
};
struct transition_table : boost::mpl::vector<
boost::msm::front::Row<Init, boost::msm::front::none, State1>
> { };
using initial_state = InitState;
};
using Fsm = boost::msm::back::state_machine<FsmDef>;
Fsm fsm;
How can I construct fsm
and initialize private data for FsmDef
. The same thing with State1.
FsmDef
can be non default constructible. ButState1
need to be default constructible.Here is a way to pass arguments to
FsmDef
.Running demo https://wandbox.org/permlink/ZhhblHFKYWd3ieDK
Fsm
,boost::msm::back::state_machine<FsmDef>
has the constructor that has the same parameters asFsmDef
. AFAIK, it is not explicitly documented.Here is the code that defining the constructor.
https://github.com/boostorg/msm/blob/boost-1.64.0/include/boost/msm/back/state_machine.hpp#L1625