subscribe to image transport with additional argument

asked 2021-05-05 03:54:09 -0600

gab27 gravatar image

Hi

I would like to subscribe to multiple image topics with the same callback function. I have the following code:

in the .hpp file:

std::vector<image_transport::Subscriber> image_subs;

cpp. file constructor:

for (const auto& topic : in_image_topic_names) {
  image_subs.push_back(img_transport.subscribe(topic, 1, boost::bind(&Class::imageCallback, "topic")));
}

the function in the cpp.

void Class::imageCallback(const sensor_msgs::ImageConstPtr& image_msg, const std::string& topic_name) {
   return
}

I get the following error:

from /home/user/catkin_ws/src/color_filter/package/src/class_node.cpp:1:
/usr/include/boost/function/function_template.hpp: In instantiation of ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t<boost::_bi::unspecified, void (Class::*)(const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const std::__cxx11::basic_string<char>&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<const char*> > >; R = void; T0 = const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&]’:
/usr/include/boost/function/function_template.hpp:931:38:   required from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (Class::*)(const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const std::__cxx11::basic_string<char>&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<const char*> > >; R = void; T0 = const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&]’
/usr/include/boost/function/function_template.hpp:720:7:   required from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_<(! boost::is_integral<Functor>::value), int>::type) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (Class::*)(const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const std::__cxx11::basic_string<char>&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<const char*> > >; R = void; T0 = const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&; typename boost::enable_if_<(! boost::is_integral<Functor>::value), int>::type = int]’
/usr/include/boost/function/function_template.hpp:1068:16:   required from ‘boost::function<R(T0)>::function(Functor, typename boost::enable_if_<(! boost::is_integral<Functor>::value), int>::type) [with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void (Class::*)(const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const std::__cxx11::basic_string<char>&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<const char*> > >; R = void; T0 = const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&; typename boost::enable_if_<(! boost::is_integral<Functor>::value), int>::type = int]’
/home/user/catkin_ws/src/package/Class/include/Class/Class.hpp:112:123:   required from here
/usr/include/boost/function/function_template.hpp:158:11: error: no match for call to ‘(boost::_bi::bind_t<boost::_bi::unspecified, void (Class::*)(const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const std::__cxx11::basic_string<char>&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<const char*> > >) (const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&)’
158 |           BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
  |           ^~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/artifact_color_filter_node.dir/build.make:63: CMakeFiles/Class_node.dir/src/Class_node.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1404: CMakeFiles/Class_node.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

Maybe someone knows what's wrong?

edit retag flag offensive close merge delete