error in using boost::bind to pass parameter
I'm new to ros and boost programming. From ros wiki and google, I know I can use boost::bind to transfer parameter to callback function. So I try to use it build a service server with parameter. But I keep meeting mismatching problem. When I try to find answer in ros community, I only find answers about subscriber. So i pose this question.
the code of bare function:
bool control_test(bebop_test::ControlSrv::Request &req, bebop_test::ControlSrv::Response &res, bebop_command *bebop_cmd){/**/}
code in main:
ros::ServiceServer bebop_server = nh.advertiseService("bebop_srv", boost::bind(&control_test, _1, _2, &bebop_cmd) );
and the error:
> Errors << bebop_test:make
> /home/simon/parrot_ws/logs/bebop_test/build.make.008.log /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:
> In function ‘int main(int, char**)’:
> /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:49:130:
> error: no matching function for call
> to
> ‘ros::NodeHandle::advertiseService(const
> char [10], boost::_bi::bind_t<bool,
> bool
> (*)(bebop_test::ControlSrvRequest_<std::allocator<void>
> >&, bebop_test::ControlSrvResponse_<std::allocator<void>
> >&, bebop_command*), boost::_bi::list3<boost::arg<1>,
> boost::arg<2>,
> boost::_bi::value<bebop_command*> >
> >)’
> ros::ServiceServer bebop_server = bebop_cmd.nh_.advertiseService("bebop_srv", boost::bind(&control_test, _1, _2,
> &bebop_cmd) );
> ^ In file included from
> /opt/ros/kinetic/include/ros/ros.h:45:0,
> from /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:1:
> /opt/ros/kinetic/include/ros/node_handle.h:879:17:
> note: candidate: template<class T,
> class MReq, class MRes>
> ros::ServiceServer
> ros::NodeHandle::advertiseService(const
> string&, bool (T::*)(MReq&, MRes&),
> T*) ServiceServer
> advertiseService(const std::string&
> service, bool(T::*srv_func)(MReq &,
> MRes &), T *obj)
> ^ /opt/ros/kinetic/include/ros/node_handle.h:879:17:
> note: template argument
> deduction/substitution failed:
> /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:49:130:
> note: mismatched types ‘bool
> (T::*)(MReq&, MRes&)’ and
> ‘boost::_bi::bind_t<bool, bool
> (*)(bebop_test::ControlSrvRequest_<std::allocator<void>
> >&, bebop_test::ControlSrvResponse_<std::allocator<void>
> >&, bebop_command*), boost::_bi::list3<boost::arg<1>,
> boost::arg<2>,
> boost::_bi::value<bebop_command*> > >’
> ros::ServiceServer bebop_server = bebop_cmd.nh_.advertiseService("bebop_srv", boost::bind(&control_test, _1, _2,
> &bebop_cmd) );
> ^ In file included from
> /opt/ros/kinetic/include/ros/ros.h:45:0,
> from /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:1:
> /opt/ros/kinetic/include/ros/node_handle.h:924:17:
> note: candidate: template<class T,
> class MReq, class MRes>
> ros::ServiceServer
> ros::NodeHandle::advertiseService(const
> string&, bool
> (T::*)(ros::ServiceEvent<MReq,
> MRes>&), T*) ServiceServer
> advertiseService(const std::string&
> service,
> bool(T::*srv_func)(ServiceEvent<MReq,
> MRes>&), T *obj)
> ^ /opt/ros/kinetic/include/ros/node_handle.h:924:17:
> note: template argument
> deduction/substitution failed:
> /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:49:130:
> note: mismatched types ‘bool
> (T::*)(ros::ServiceEvent<MReq,
> MRes>&)’ and ‘boost::_bi::bind_t<bool,
> bool
> (*)(bebop_test::ControlSrvRequest_<std::allocator<void>
> >&, bebop_test::ControlSrvResponse_<std::allocator<void>
> >&, bebop_command*), boost::_bi::list3<boost::arg<1>,
> boost::arg<2>,
> boost::_bi::value<bebop_command*> > >’
> ros::ServiceServer bebop_server = bebop_cmd.nh_.advertiseService("bebop_srv", boost::bind(&control_test, _1, _2,
> &bebop_cmd) );
> ^ In file included from
> /opt/ros/kinetic/include/ros/ros.h:45:0,
> from /home/simon/parrot_ws/src/bebop_test/src/bebop_server_re.cpp:1 ...