Using subscriber/callback function inside of a class C++
For the life of me I cannot seem to figure out why this code is not working and throws up a lot of errors:
class Example {
public:
Example(ros::NodeHandle n )
{
sub = n.subscribe("/camera/depth_registered/points", 1000, &this->callBack);
}
void callBack(const sensor_msgs::PointCloud2Ptr& msg)
{
}
protected:
ros::Subscriber sub;
};
I have initialised the ros::Subscriber sub
inside of the class members but cannot seem to figure out why it's giving me an error.
Any ideas?
EDIT:
Here are the error messages:
error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [32], int, <unresolved overloaded function type>)’
/src/talker.cpp:11:71: note: candidates are:
/opt/ros/hydro/include/ros/node_handle.h:379:14: note: template<class M, class T> ros::Subscriber ros::NodeHandle::subscribe(const string&, uint32_t, void (T::*)(M), T*, const ros::TransportHints&)
What exact errors? When are you getting them? During compile or when running? Initial guess: Try adding a this to the subscribe call an specify the classname instead of this-> for the subscribe.