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

Revision history [back]

Ok now I know...

I tried to initialise it in declaration part of the NodeClass not inside any method. And this just doesn't work in C++. If you put it in constructor it will work like in the following example:

// ROS includes
#include <ros/ros.h>
#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include <tf/transform_listener.h>
#include <tf2_ros/buffer.h>
#include <tf2_ros/transform_listener.h>
#include <sensor_msgs/PointCloud.h>
#include <laser_geometry/laser_geometry.h>

// ROS message includes
#include <sensor_msgs/LaserScan.h>


//####################
//#### node class ####
class NodeClass
{
    //
    public:

    NodeClass();

    ros::NodeHandle nodeHandle;
    // topics to publish
    message_filters::Subscriber<sensor_msgs::LaserScan> * topicSub_LaserFront;
    message_filters::Subscriber<sensor_msgs::LaserScan> * topicSub_LaserBack;
    message_filters::TimeSynchronizer<sensor_msgs::LaserScan, sensor_msgs::LaserScan> *sync;
    tf::TransformListener listener_;
    tf2_ros::Buffer buffer;
    tf2_ros::TransformListener* tf_listener;
    laser_geometry::LaserProjection projector_;
    ros::Publisher topicPub_LaserUnified;

}

NodeClass::NodeClass() {

    tf_listener = new TransformListener(buffer);
}