[StateChart] How to pass arguments to a state constructor when doing state transition?

Hi all, I have a state like this, which has two parameters in it's constructor except the ctx. I want to know how to pass these two arguments to the constructor, when do state transition? I have tried this: transit< RepeatedPlayingState , 1, 2>(); But it cause compiling error? How to do this? I want to pass something to a new entered state. Thanks! class RepeatedPlayingState: public state< RepeatedPlayingState, PlayingState
{ public: RepeatedPlayingState( my_context ctx , long start_pos, long end_pos) : my_base( ctx ){ context< PlayerFsm >().player_.PlayFromTo(start_pos, end_pos); } }; Best Regards Hill

Hi
I have a state like this, which has two parameters in it's constructor except the ctx. I want to know how to pass these two arguments to the constructor, when do state transition? I have tried this: transit< RepeatedPlayingState , 1, 2>();
But it cause compiling error? How to do this? I want to pass something to a new entered state.
Short answer: By design you can't. The reasons are as follows: - In general, a transition must be able to enter multiple states at once (for the case when there are nested and/or orthogonal states). If you were able to pass arguments to transit like you ask then to what state constructors are the arguments forwarded? To just the first entered, all of them, or just a few select ones? - Moreover, the same state can be the target of multiple different transitions. If just one of those transitions wanted to pass arguments, then all other incoming transitions would be forced to pass the same arguments too. So, for the general case passing arguments to transit would become unworkable very quickly. However, you can use simple_state::triggering_event() to get the triggering event inside the state constructor. Note: The states that do so must derive from state instead of simple_state. HTH & Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (2)
-
Andreas Huber
-
Zhu Bicen