[statechart] friend state can't call overloaded member functions in machine class
Hi, if one want to centralize all transition callbacks into the machine itself it's a good way to declare the states as friends and call the machine member functions which should (of course) private. But boost::statechart has problems if the member functions in the machine class are overloaded. Then the friend declaration is ignored by the compiler. Here is a snippet to reproduce the error: struct Active; class CoreApp : public boost::statechart::state_machine< CoreApp, Active > { friend struct Active; public: CoreApp() { initiate(); } private: void doInStateReaction(const EvNext &) {} void doInStateReaction(const EvBack &) {} ///< uncomment this line to resolve the error }; struct Active : boost::statechart::simple_state< Active, CoreApp > { typedef boost::mpl::list < //sc::in_state_reaction < EvBack, CoreApp, &CoreApp::doInStateReaction >, sc::in_state_reaction < EvNext, CoreApp, &CoreApp::doInStateReaction > > reactions; }; As one can see two functions doInStateReaction() are defined in the state machine class. Comment the second one out and it compiles. This problem occurs too if one uses a templated event which calls a templated function. A easy solution to this problem is to rename the functions slightly but I hope there is a better way. Has anyone an idea to catch this? David
Hi David [snip]
class CoreApp : public boost::statechart::state_machine< CoreApp, Active > { friend struct Active; public: CoreApp() { initiate(); }
private: void doInStateReaction(const EvNext &) {} void doInStateReaction(const EvBack &) {} ///< uncomment this line to resolve the error };
struct Active : boost::statechart::simple_state< Active, CoreApp > { typedef boost::mpl::list < //sc::in_state_reaction < EvBack, CoreApp, &CoreApp::doInStateReaction
, sc::in_state_reaction < EvNext, CoreApp, &CoreApp::doInStateReaction > reactions; };
As one can see two functions doInStateReaction() are defined in the state machine class. Comment the second one out and it compiles. This problem occurs too if one uses a templated event which calls a templated function. A easy solution to this problem is to rename the functions slightly but I hope there is a better way. Has anyone an idea to catch this?
This has nothing to do with Boost.Statechart but is, IIRC, a plain old C++ "problem". Replace with the following lines and everything should work: sc::in_state_reaction< EvBack, CoreApp, (void (CoreApp::*)(const EvBack &)) &CoreApp::doInStateReaction >, sc::in_state_reaction< EvNext, CoreApp, (void (CoreApp::*)(const EvNext &)) &CoreApp::doInStateReaction > Hope I got the syntax right... HTH, -- 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
-
David Matz