class construction error when using tf2_ros::Buffer
Hi all, I am trying to use tf2_ros::Buffer in a simple code. When I put it in the main function, everything works fine. But when put in a class, building error occurs. The code is like this:
#include <ros/ros.h>
#include <tf2_ros/buffer.h>
#include <tf2_ros/transform_listener.h>
#include <geometry_msgs/TransformStamped.h>
#include <geometry_msgs/Twist.h>
class test_class
{
private:
double start;
double duration;
ros::Time start_time;
ros::Time end_time;
std::string robot_name;
tf2_ros::Buffer tf_buffer; // problem
tf2_ros::TransformListener* tfListener;
geometry_msgs::TransformStamped transformStamped;
public:
std::string space_name;
std::string node_name;
test_class()
{
space_name = ros::this_node::getNamespace();
node_name = ros::this_node::getName();
}
~test_class()
{}
bool initialize(const ros::NodeHandle& n)
{
ROS_INFO("Class auto_mav_flight initialized done!");
return true;
}
void timer_callback(const ros::TimerEvent& event)
{
ROS_INFO("Timer Callback triggered.");
return;
}
};
int main(int argc, char** argv)
{
ros::init(argc, argv, "auto_mav_node");
ros::NodeHandle node;
ROS_WARN("The node is initilized and started.");
test_class amf = test_class();
amf.initialize(node);
ros::Timer timer_1 = node.createTimer(ros::Duration(0.5), &test_class::timer_callback, &amf);
ros::spin();
return EXIT_SUCCESS;
}
and the building error information is:
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp: In function ‘int main(int, char**)’:
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:73:44: error: no matching function for call to ‘test_class::test_class(test_class)’
test_class amf = test_class();
^
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:73:44: note: candidates are:
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:26:2: note: test_class::test_class()
test_class()
^
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:26:2: note: candidate expects 0 arguments, 1 provided
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:9:7: note: test_class::test_class(test_class&)
class test_class
^
/home/arkin/ros_code/sandbox/auto_mav_sandbox/src/auto_mav_flight/src/node_main.cpp:9:7: note: no known conversion for argument 1 from ‘test_class’ to ‘test_class&’
make[2]: *** [auto_mav_flight/CMakeFiles/auto_mav_flight_node.dir/src/node_main.cpp.o] Error 1
make[1]: *** [auto_mav_flight/CMakeFiles/auto_mav_flight_node.dir/all] Error 2
make: *** [all] Error 2
I found that if I comment the code line:
tf2_ros::Buffer tf_buffer;
the error disappear.
Why the tf2_ros::Buffer can cause problem of class construction even I just declare it as a member of class?
Any help will be appreciated.
Thanks in advance.