Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 98

boost::bind errors in subscriber callback

$
0
0
Hello. New to ROS, Boost, and if I'm quite honest, C++ in general. Basically, I am trying to pass a few parameters to a callback function using boost::bind, but am unable to compile. I am running into the same issue as [this question](https://answers.ros.org/question/121831/boostbind-errors-in-subscriber-callback-functions/), among others, but none of the solutions I've found seem to be working for me. Based on some of the things I found, I had some suspicions that I may not have had bind at all, so I made changes to try and do so, with no change in results. relevant source: #include "ros/ros.h" #include //#include void mapcallback(const nav_msgs::OccupancyGrid::ConstPtr& msg, int* k)//Map_Info* mapdata) { //doing stuff } int main(int argc, char **argv) { ros::init(argc, argv, "mapper"); ros::NodeHandle n; int test; //boost::bind(&mapcallback, _1, test); ros::Subscriber sub2=n.subscribe("map",1, boost::bind(&mapcallback, _1, &test)); while (ros::ok()) { ros::spinOnce(); sleep(2); } return 0; } Ultimately, test is going to be replaced with a class generated by a different subscriber, but right now I'm just trying to get the basic case to compile. I've tried both with and without the pointers in the boost::bind, with no difference. Also, the include makes no difference, and the compiler doesn't complain about the currently commented line. The error I am getting is error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [4], int, boost::_bi::bind_t>>&, int), boost::_bi::list2, boost::_bi::value>>)’ ros::Subscriber sub2=n.subscribe("map",1, boost::bind(&mapcallback, _1, test)); followed by a bunch of candidates, and then /opt/ros/kinetic/include/ros/node_handle.h:835:14: note: candidate expects 1 argument, 3 provided if I add the line `find_package(Boost REQUIRED COMPONENTS bind)` to my CMakeLists.txt, it does stop earlier saying that it is unable to find package bind, but a different package (I thing it was system) worked without issue. I've been fighting this issue for most of a day now, so help would be very appreciated.

Viewing all articles
Browse latest Browse all 98

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>