ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Passing class pointer as argument to subscribe

asked 2023-01-24 23:08:53 -0500

mgmike1023 gravatar image

I have a Base, Derived class structure and want to pass in the pointer to the base class as an argument. Shouldn't passing the pointer to the base class be the same as the memory address?

Base* base = new Derived1();

ros::Subscriber sub = nh.subscribe(topic, 100, &Base::callback, base);

I thought it should work but I get the following error:

error: no matching function for call to ‘ros::NodeHandle::subscribe(std::__cxx11::string&, int, Eigen::Matrix4d (Base::)(const PointCloud2ConstPtr&), Base&)’ ros::Subscriber sub = nh.subscribe(topic, 100, &Base::callback, base);

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-01-27 16:23:33 -0500

mgmike1023 gravatar image

Okay turns out my callback function as a return type instead of void. That was it.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-01-24 23:08:53 -0500

Seen: 71 times

Last updated: Jan 27 '23