boost::bind errors in subscriber callback
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, 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 <nav_msgs/OccupancyGrid.h>
//#include <boost/bind.hpp>
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<void, void (*)(const boost::shared_ptr<const nav_msgs::OccupancyGrid_<std::allocator<void> > >&, int), boost::_bi::list2<boost::arg<1>, boost::_bi::value<int> > >)’
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.