Robotics StackExchange | Archived questions

Error: No match for call to 'boost::…'

I am trying to modify another code. Just wanted to add another subscriber to it. This is the skeleton of the code:

namespace my_server
{
    a_server::a_server(ros::NodeHandle n)
    : nh()
    {
        ros::NodeHandle n(n_);
        sub1 = new message_filters::Subscriber<sensor_msgs::PointCloud2> (nh(), "/x", 5);
        sub2 = new tf::MessageFilter<sensor_msgs::PointCloud2> (*sub1, sub3, xyz, 5);
        sub2->registerCallback(boost::bind(&a_server::callback, this, _1));
    }
    a_server::~a_server()
    {
    .....
    }

    void a_server::callback(const sensor_msgs::PointCloud2::ConstPtr& cl)
    {
    ....
    }
}

And here is the header file:

namespace my_server
{
    class a_server
    {
        public:
        a_server(ros::NodeHandle n_ = ros::NodeHandle("~"));
        virtual ~a_server();

        virtual void callback(const sensor_msgs::PointCloud2::ConstPtr& cl);
        protected:
            ros::NodeHandle n;
            message_filters::Subscriber<sensor_msgs::PointCloud2>* sub1;
            tf::MessageFilter<sensor_msgs::PointCloud2>* sub2;
            tf::TransformListener sub3;
    }
}

Now I want to add another subscriber to it. Do not need to bind it with previous subscriber. I am doing it by adding this line after previous subscribers.

ros::Subscriber  sub4 = nh.subscribe<geometry_msgs::Point>("/y", 1, &a_server::callback2);

And added a callback function after void a_server::callback:

void a_server::callback2(geometry_msgs::Point &a)
{
    ....
}

And this to header file under protected: void callback2(geometry_msgs::Point &a);

This is the error that i am getting :

Error: 
no match for call to ‘(boost::_mfi::mf1<void, my_server::a_server, geometry_msgs::Point_<std::allocator<void> >&>) (const boost::shared_ptr<const geometry_msgs::Point_<std::allocator<void> > >&)’
BOOST_FUNCTION_RETURN(boost::mem_fn(*f)(BOOST_FUNCTION_ARGS));

I understand this has something to do with boost::bind usage in previous subscribers. But I don't want to change them. Just need to add another subscriber whose callback function will update a global variable that will in return be used by previous callback function.

Asked by usamamaq on 2019-08-22 08:36:29 UTC

Comments

ros::Subscriber  sub4 = m_nh.subscribe<geometry_msgs::Point>("/y", 1, &a_server::callback2);

I believe the prototype is "topic name, callback, queue size".

Asked by gvdhoorn on 2019-08-22 09:28:13 UTC

Sorry i didn't get it. Isn't this the syntax "topic name, queue size, callback" for node.subscriber like in ROS tutorial:

ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);

Asked by usamamaq on 2019-08-22 09:44:44 UTC

Answers

So after loosing precious 6 hours. This is how it is solved. Subscriber was added like this:

ros::Subscriber sub4 = nh.subscribe<geometry_msgs::Point>("/y", 1, boost::bind(&a_server::callback2, this, _1));

Callback function was written like this:

void a_server::callback2(const geometry_msgs::Point::ConstPtr& a)
{
    ....
}

Header file was added with this under Public:

void callback2(const geometry_msgs::Point::ConstPtr& a);

Asked by usamamaq on 2019-08-22 10:48:04 UTC

Comments

so what was the problem exactly? I am having a similar problem, that I've described briefly here: https://stackoverflow.com/questions/62345576/error-no-match-for-call-to-boost-mfimf1void

Asked by azerila on 2020-06-12 08:51:20 UTC