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

Revision history [back]

click to hide/show revision 1
initial version

Hi Ammar,

I think your have this problem because your subscriber object doesn't live outside its scope (constructor). You need to declare it as a private object in your class

private:
    ros:Subscriber ...

then you can initialize it in the constructor. In the main function, when you create the object, you will have a running subscriber in your object.

Hi Ammar,

I think your have this problem because your subscriber object doesn't live outside its scope (constructor). You need to declare it as a private object in your class

private:
    ros:Subscriber ...
sub;

then you can initialize it in the constructor. constructor:

sub = n.subscribe("chatter", 1000, &Listener::callback, &listener);

In the main function, when you create the object, you will have a running subscriber in your object.

Hi Ammar,

I think your you have this problem because your subscriber object doesn't live outside its scope (constructor). You need to declare it as a private object in your class

private:
    ros:Subscriber sub;

then you can initialize it in the constructor:

sub = n.subscribe("chatter", 1000, &Listener::callback, &listener);

In the main function, when you create the object, you will have a running subscriber in your object.