No Matching Member Function for Call to Subscribe
I am calling subscribe, passing in a class member function and this
current instance.
Everything I am doing seems correct to me, but I'm getting No matching member function for call to subscribe. I have annotated the point where the error occurs.
I thought it could be my being rusty with C++ and not initializing my private reference to the nodehandle correctly, but using the parameter to the constructor n
has the same effect.
Class declaration:
#pragma once
#include <spencer_tracking_msgs/TrackedPersons.h>
#include <spencer_tracking_msgs/TrackedPerson.h>
#include <geometry_msgs/Point.h>
#include <ros/ros.h>
#include <ros/package.h>
#include <functional>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Eigenvalues>
#include <deque>
#include <boost/bind.hpp>
/*
All function and class declarations pertaining to person, object
tracking goes here.
All names declared in the namespace must be unique.
*/
using PTCallback = std::function<void(Eigen::Vector2f)>;
const std::string PTRACK_TOPICNAME = "/spencer/perception/tracked_persons";
namespace followlib
{
class PeopleTracker
{
public:
/**
* @brief Create a PeopleTracker with callback for tracked person coordinates
* @param n: node handle of core app
* @param cb: callback accepting vector2f points, bound using std::mem_fn()
***/
PeopleTracker(const ros::NodeHandle &n, const PTCallback &cb);
PeopleTracker (const PeopleTracker&) = delete;
PeopleTracker& operator= (const PeopleTracker&) = delete;
private:
void p_SubCb(const spencer_tracking_msgs::TrackedPersons::ConstPtr &msg);
private:
const ros::NodeHandle &p_rosnode;
const PTCallback &p_cb;
ros::Subscriber p_ptSub;
};
}
Class definition:
#include "tracking.h"
namespace followlib
{
PeopleTracker::PeopleTracker(const ros::NodeHandle &n, const PTCallback &cb):
p_rosnode(n), p_cb(cb) {
p_ptSub = n.subscribe("spencer/perception/tracked_persons",
1000, &PeopleTracker::p_SubCb, this); // error, no matching member function for call to 'subscribe'
}
void PeopleTracker::p_SubCb(const spencer_tracking_msgs::TrackedPersons::ConstPtr &msg)
{
const spencer_tracking_msgs::TrackedPersons &m = *msg;
if (m.tracks.size() > 0)
{
const geometry_msgs::Point &p = m.tracks[0].pose.pose.position;
Eigen::Vector2f v (p.x, p.y);
p_cb(v);
}
}
}
Truncated Compiler Error:
/home/rpg711/kinetic_workspace/sandbox/cs403-semester-project/src/libs/tracking.cpp:9:78: error: no matching function for call to ‘ros::NodeHandle::subscribe(const string&, int, void (followlib::PeopleTracker::*)(const ConstPtr&), followlib::PeopleTracker*) const’
p_ptSub = n.subscribe(PTRACK_TOPICNAME, 1000, &PeopleTracker::p_SubCb, this);
^
In file included from /opt/ros/kinetic/include/ros/ros.h:45:0,
from /home/rpg711/kinetic_workspace/sandbox/cs403-semester-project/include/tracking.h:6
I have also tried using to no success:
p_ptSub = n.subscribe("spencer/perception/tracked_persons",
1000, boost::bind(&PeopleTracker::p_SubCb, this, _1)); // error, no matching member function for call to 'subscribe'
Edit:
I have also tried this to the same error:
void (PeopleTracker::* fn) (spencer_tracking_msgs::TrackedPersons::ConstPtr) = &PeopleTracker::p_SubCb;
p_ptSub = n.subscribe(PTRACK_TOPICNAME, 1, fn, this);
What is going on?
Welcome! Can you please update your question with a copy/paste of the error?
@jayess yep, added it.