在类中声明tf2_ros::Buffer时生成错误
Building error when declare tf2_ros::Buffer in class
我正在尝试在一个简单的代码中使用tf2_ros::Buffer。当我把它放在主功能中时,一切都很好。但当放入类中时,会发生构建错误。代码如下:
#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 line
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;
}
构建错误信息为:
/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
我发现,如果我对声明tf2_ros::buffer:的代码行进行注释
tf2_ros::Buffer tf_buffer;
错误消失。
为什么tf2_ros::Buffer会导致类构造问题,即使我只是将其声明为类的成员?
任何帮助都将不胜感激。
提前谢谢。
从此:
/home/arkin/ros_code/sharbox/auto_mav_sharbox/src/auto_mav_flight/src/node_main.cpp:26:2:注意:候选者需要0个参数,而提供了1个/home/arkin/ros_code/sharbox/auto_mav_sharbox/src/auto_mav_flight/src/nod_main.cpp:9:7:注意:test_class::test_cclass(test_class&)
您似乎正在调用test_class
的复制构造函数(可能隐藏在ROS层中,通过尝试将test_class
作为函数参数传递或在使用容器时传递)。
从tf2_ros::Buffer头中,它继承自BufferCore,后者包含一个boost::mutex
(除其他外,可能有多个不可复制的属性),该属性不可复制构造。这使得tf2_ros::Buffer
不可复制构造。由于test_class
不定义复制构造函数并且包含不可复制的属性,因此编译器无法生成复制构造函数,并且在尝试调用复制构造函数时无法编译。
供参考:http://en.cppreference.com/w/cpp/language/copy_constructor
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- MSVC多行宏编译器错误
- 在类中声明tf2_ros::Buffer时生成错误
- "no match for ‘operator>>’ in ‘inputFile >> buffer"错误?
- Unmapping Buffer时出现分段错误