[statechart] post_event() and Boost.Bind
Currently I don't understand why the following code dosn't compile (with VC 8.0). I simply try to bind the post_event() method from the state_machine to a function object. To illustrate the problem I've added the following code to the Camera.hpp file of the Camera example from the Statechart library: #include <boost/function.hpp> #include <boost/bind.hpp> <snip> struct Camera : sc::state_machine< Camera, NotShooting > { // @test start typedef boost::function< void( const event_base_type& ) >process_event_fun; typedef boost::function< void( const event_base_type& ) > post_event_fun; process_event_fun process_event_fun_; post_event_fun post_event_fun_; Camera() { process_event_fun_ = boost::bind( &Camera::process_event, boost::ref( *this ), _1 ); // the following line doesn't compile with VC 8.0 // post_event_fun_ = boost::bind( &Camera::post_event, boost::ref( *this ), _1 ); } // @test end bool IsMemoryAvailable() const { return true; } bool IsBatteryLow() const { return false; } }; After uncommenting the marked line the compiler produce more than 200 error messages: A function template has too few arguments. But the line above compiles very well and the process_event() method has the same signature. The post_event() method is polymorphic. But this shouldn't be a problem. Should it?
Hi,
After uncommenting the marked line the compiler produce more than 200 error messages: A function template has too few arguments. But the line above compiles very well and the process_event() method has the same signature.
In the StateChart documentation I can see that the difference between post_event and process_event is that the former has 2 overloads. So I guess you'll have to specify which one you wish to use. Something like: bind(static_cast<void (Camera::*)(const event_base&)>(&Camera::post_event), boost::ref(*this ), _1 ); Bruno
Thanks for your helpful advice. The following line post_event_fun_ = boost::bind( static_cast<void (Camera::*)(const event_base_type&)>(&Camera::post_event), boost::ref(*this ), _1 ); works perfect. I thought your way too. There are 2 overloads of post_event(). But I hoped that Boost.Bind could solve this in any magic way. And until now I was not aware about the option to cast a method. So I have a solution and learned something new. Thats great. "Bruno Lalande" <bruno.lalande@gmail.com> schrieb im Newsbeitrag news:9bea5ee0803271547t467b6d3dr9867f899dc1da9db@mail.gmail.com...
Hi,
After uncommenting the marked line the compiler produce more than 200 error messages: A function template has too few arguments. But the line above compiles very well and the process_event() method has the same signature.
In the StateChart documentation I can see that the difference between post_event and process_event is that the former has 2 overloads. So I guess you'll have to specify which one you wish to use. Something like:
bind(static_cast<void (Camera::*)(const event_base&)>(&Camera::post_event), boost::ref(*this ), _1 );
Bruno
participants (2)
-
Bruno Lalande
-
Commander Pirx