a error occurs when using boost::bind to the basic listener.cpp
I made a mistake in previous question here. Hence, I closed it. Here is my new question...
I am using boost bind to subscribe to several topics, following this.
I programmed a basic listener.cpp according to the wiki, and added boost::bind to it. Unfornately, the errors occured.
Can anyone help me? Many thanks.
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <boost/bind.hpp>
void chatterCallback(const std_msgs::String::ConstPtr& msg) {
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int main(int argc, char **argv) {
ros::init(argc, argv, "listener");
int i = 0;
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter0", 1000, boost::bind(chatterCallback, _1, i));
ros::spin();
return 0;
}
Here is the compiling result.
In file included from /usr/include/boost/bind.hpp:22:0,
from /opt/ros/indigo/include/ros/publisher.h:35,
from /opt/ros/indigo/include/ros/node_handle.h:32,
from /opt/ros/indigo/include/ros/ros.h:45,
from /home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:1:
/usr/include/boost/bind/bind.hpp: In instantiation of ‘struct boost::_bi::result_traits<boost::_bi::unspecified, void (*)(const boost::shared_ptr<const std_msgs::String_<std::allocator<void> > >&)>’:
/usr/include/boost/bind/bind_template.hpp:15:48: required from ‘class boost::_bi::bind_t<boost::_bi::unspecified, void (*)(const boost::shared_ptr<const std_msgs::String_<std::allocator<void> > >&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >’
/home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:15:91: required from here
/usr/include/boost/bind/bind.hpp:69:37: error: ‘void (*)(const boost::shared_ptr<const std_msgs::String_<std::allocator<void> > >&)’ is not a class, struct, or union type
typedef typename F::result_type type;
^
/home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp: In function ‘int main(int, char**)’:
/home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:15:92: error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [9], int, boost::_bi::bind_t<boost::_bi::unspecified, void (*)(const boost::shared_ptr<const std_msgs::String_<std::allocator<void> > >&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >)’
ros::Subscriber sub = n.subscribe("chatter0", 1000, boost::bind(chatterCallback, _1, i));
^
/home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:15:92: note: candidates are:
In file included from /opt/ros/indigo/include/ros/ros.h:45:0,
from /home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:1:
/opt/ros/indigo/include/ros/node_handle.h:401:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), T*, const ros::TransportHints&)
Subscriber subscribe(const std::string& topic, uint32_t queue_size, void(T::*fp)(M), T* obj,
^
/opt/ros/indigo/include/ros/node_handle.h:401:14: note: template argument deduction/substitution failed:
/home/alex/Documents/Tutorials/ROS/wiki/catkin_ws/src/beginner_tutorials/src/listener_bind.cpp:15:92: note: mismatched types ‘void (T::*)(M)’ and ‘boost::_bi::bind_t<boost::_bi::unspecified, void (*)(const boost ...