title: ROS subscribe callback - using boost::bind with member functions
body: <p>I'm trying to subscribe to different topics in ROS (one for every vehicle that pops up) using the same callback for all of them. The idea is that <code>boost::bind</code> will pass the topic name as an additional argument so I know which vehicle I should access in the callback.</p>
  
  <p>The problem is that, even though I've gone through multiple questions on the topic, none of the solutions seem to work.</p>
  
  <p>Basically, I have the following class <code>VOBase</code> containing a <code>std::map&lt;std::string, VOAgent*&gt; agents_</code> with a member function as follows:</p>
  
  <pre><code>void VOBase::callback_agentState(const custom_msgs::VState::ConstPtr&amp; vStateMsg,
          std::string topic) {
      // [...] regex to find agent name from topic string
      std::string agent_name = match.str();
      // [...] Check if agent name exists, else throw exception
  
      // Process message
      agents_[agent_name]-&gt;pos_ = vStateMsg-&gt;pose.position;  // etc.
  }
  </code></pre>
  
  <p>Which I'm calling through this subscription:</p>
  
  <pre><code>void VOBase::callback_agentList(const custom_msgs::VehicleList&amp; vehListMsg) {
      // [...] New agent/vehicle found: process vehListMsg and get agent_name string
  
      // Subscribe to VState
      topic_name = agent_name + "/state_estimate";
      subscribers_[topic_name] = nodeHandlePtr-&gt;subscribe&lt;custom_msgs::VState&gt;(topic_name, 1,
          std::bind(&amp;VOBase::callback_agentState, this, _1, topic_name));
  }
  </code></pre>
  
  <p>However, I'm getting a <code>template argument deduction/substitution failed</code> with all the candidates and this error:</p>
  
  <pre><code>mismatched types ‘std::reference_wrapper&lt;_Tp&gt;’ and ‘VO::VOBase*’
                      typename add_cv&lt;_Functor&gt;::type&amp;&gt;::type&gt;()(
  </code></pre>
  
  <p>I've tested a number of the solutions out there, e.g. using <code>std::ref(this)</code> to get a <code>std::reference_wrapper&lt;_Tp&gt;</code> instead of a <code>VO::VOBase*</code> (the reference doesn't survive though: <code>use of deleted function</code>), using <code>boost::bind</code> instead of <code>std::bind</code> (but it should be all the same since C++11), with and without the <code>...::ConstPtr</code> for the ROS message in the callback function arguments (and in the <code>subscribe&lt;acl_msgs::ViconState::ConstPtr&gt;</code>, etc. So I'm just juggling with partial solutions and their permutations here...</p>
  
  <p>Any clues?</p>