Can't use subscribe from inside c++ class
I am having trouble getting ros inside a c++ class. Running Windows 7, compiling with Visual Studio 2010.
I started by trying to adapt the "listener" project in rosws, which contains a visualstudio example that compiles and runs ok.
However, even if I simply put everything inside a class, I get this error:
Error 30 error C2660: 'ros::NodeHandle::subscribe' : function does not take 3 arguments C:\opt\rosws\fuerte\sdk-tutorials\listener\listener.cpp 59 1 listener
This simple example replicates the problem:
#include "stdafx.h"
#include <iostream>
#include <ros/ros.h>
#include <std_msgs/String.h>
#include <sstream>
class listener {
public:
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int mymain(int argc, char** argv)
{
ros::init(argc, argv, "listener");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("chatter", 1000, &listener::chatterCallback);
ros::spin();
return 0;
}
};
So you see that I am just sticking everything inside a class so that I can create and manipulate instances of my objects.
Why does the compiler not find the correct subscribe function now? If I just compile the code without the class, it works.
I checked out the "talker" project which used an "advertise" function, but that one works ok if I stick it inside a class.