Re: [boost] [MSM] passing constructor arguments to frontend asreference.

Hi, All
we might found a problem when passing constructor arguments to the front end in case constructor arguments are passed by reference. In that case you do not pass the argument as reference in the first place rather copy construct a new object and pass that object as reference to the front end. We looked into the preprocessor code which we believe verified our assumption:
(code snippet only contains the first part with one constructor argument!)
template < class ARG0> state_machine<Derived,HistoryPolicy,CompilePolicy >( ARG0 t0 ) :Derived( t0) ,m_events_queue() ,m_deferred_events_queue() ,m_history() ,m_event_processing(false) ,m_is_included(false) ,m_visitors() ,m_substate_list() { ::boost::mpl::for_each< seq_initial_states, ::boost::msm::wrap<mpl::placeholders::_1> > (init_states(m_states)); m_history.set_initial_states(m_states); fill_states(this); }
In our case, if we want to pass a reference, ARG0 has to be declared as follows: template < class ARG0> state_machine<Derived,HistoryPolicy,CompilePolicy >( ARG0& t0 ) :Derived( t0) ....
The "Derived" class looks like as follows: class "Derived" { public: Derived(SomeClass& cl_) {} }
Do you have any idea how to solve this?
Thanks in advance.
Richie & Michi
Hi, It's a classical issue with template arguments and something I definitely should have written in the doc. To pass arguments by reference, you need to use boost::ref (or boost::cref for const references), for example: // The "Derived" class looks like as follows: class Derived : public msm::front::state_machine_def<Derived> { public: Derived(SomeClass& cl_) {} ... } typedef msm::back::state_machine<Derived> MyFsm; SomeClass stuff; ... MyFsm fsm (boost::ref(stuff)); Thanks for pointing this out, I will update the doc. Note: I fly tomorrow to the BoostCon, so I might be a bit less responsive (jetlagged) the first few days. HTH, Christophe
participants (1)
-
Christophe Henry