ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

No Matching Member Function for Call to Subscribe

asked 2018-04-16 15:35:44 -0500

rpg711 gravatar image

updated 2018-04-16 18:35:43 -0500

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
    * @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;
    void p_SubCb(const spencer_tracking_msgs::TrackedPersons::ConstPtr &msg);

    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);


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'


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?

edit retag flag offensive close merge delete


Welcome! Can you please update your question with a copy/paste of the error?

jayess gravatar image jayess  ( 2018-04-16 17:36:21 -0500 )edit

@jayess yep, added it.

rpg711 gravatar image rpg711  ( 2018-04-16 17:48:01 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-04-16 18:53:50 -0500

rpg711 gravatar image

updated 2018-04-16 18:55:23 -0500

Well, I figured it out.

I changed my PeopleTracker constructor to:

PeopleTracker(ros::NodeHandle &n, const PTCallback &cb);

I removed the const qualifier on the ros::NodeHandle. I have no idea why this didn't work with the const qualifier, there is a const-qualified member function overload of ros::NodeHandle.subscribe() so it should be able to be called on a const reference...

Someone who reads this answer and figures out exactly why, please tell me!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-04-16 15:35:44 -0500

Seen: 1,675 times

Last updated: Apr 16 '18