【ros2订阅报错】 ros2 forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::Las

这里写自定义目录标题

  • 使用ROS2创建发布者

使用ROS2创建发布者

在创建发布者的时候,出现,如下问题,经过修改cmakeList发现并不是cmake版本问题。
···
/usr/include/c++/9/bits/alloc_traits.h:399:13: error: forming pointer to reference type ‘const std::shared_ptr >&’
399 | using pointer = Tp*;
| ^~~~~~~
/usr/include/c++/9/bits/alloc_traits.h:402:13: error: forming pointer to reference type ‘const std::shared_ptr >&’
402 | using const_pointer = const Tp*;
| ^~~~~~~~~~~~~
In file included from /usr/include/c++/9/memory:80,
from /home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/./cartographer_ros/relocation_node_main.h:21,
from /home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/cartographer_ros/relocation_node_main.cc:17:
/usr/include/c++/9/bits/unique_ptr.h: In instantiation of ‘struct std::default_delete >&>’:
/opt/ros/foxy/include/rclcpp/message_memory_strategy.hpp:119:18: required from ‘class rclcpp::message_memory_strategy::MessageMemoryStrategy >&, std::allocator >’
/opt/ros/foxy/include/rclcpp/node_impl.hpp:91:1: required by substitution of ‘template std::shared_ptr rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = sensor_msgs::msg::LaserScan_; CallbackT = std::Bind(cartographer_ros::RelocationActionServer, std::Placeholder<1>))(const std::shared_ptr >&)>; AllocatorT = std::allocator; CallbackMessageT = const std::shared_ptr >&; SubscriptionT = rclcpp::Subscription >&, std::allocator, rclcpp::message_memory_strategy::MessageMemoryStrategy >&, std::allocator > >; MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy >&, std::allocator >]’
/home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/./cartographer_ros/relocation_node_main.h:122:162: required from here
/usr/include/c++/9/bits/unique_ptr.h:71:9: error: forming pointer to reference type ‘const std::shared_ptr >&’
71 | default_delete(const default_delete<Up>&) noexcept { }
| ^~~~~~~~~~~~~~
/usr/include/c++/9/bits/unique_ptr.h:75:7: error: forming pointer to reference type ‘const std::shared_ptr >&’
75 | operator()(_Tp* __ptr) const
| ^~~~~~~~
···

原因是callback函数中的参数不得是引用的形式。需要去除&。
如下,将内容修改:

void ScanCallback(const sensor_msgs::msg::LaserScan::ConstSharedPtr &scan);

到:

void ScanCallback(const sensor_msgs::msg::LaserScan::ConstSharedPtr scan);

你可能感兴趣的:(slam源码学习,ROS技巧,自动驾驶,人工智能,机器学习)