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

这里写自定义目录标题

使用ROS2创建发布者

在创建发布者的时候,出现,如下问题,经过修改cmakeList发现并不是cmake版本问题。
···
/usr/include/c++/9/bits/alloc_traits.h:399:13: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&’
399 | using pointer = Tp*;
| ^~~~~~~
/usr/include/c++/9/bits/alloc_traits.h:402:13: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan
<std::allocator > >&’
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<const std::shared_ptr<const sensor_msgs::msg::LaserScan
<std::allocator > >&>’:
/opt/ros/foxy/include/rclcpp/message_memory_strategy.hpp:119:18: required from ‘class rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator >’
/opt/ros/foxy/include/rclcpp/node_impl.hpp:91:1: required by substitution of ‘template<class MessageT, class CallbackT, class AllocatorT, class CallbackMessageT, class SubscriptionT, class MessageMemoryStrategyT> 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_<std::allocator >; CallbackT = std::Bind<void (cartographer_ros::RelocationActionServer::(cartographer_ros::RelocationActionServer, std::Placeholder<1>))(const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&)>; AllocatorT = std::allocator; CallbackMessageT = const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&; SubscriptionT = rclcpp::Subscription<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator > >; MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, 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<const sensor_msgs::msg::LaserScan_<std::allocator > >&’
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<const sensor_msgs::msg::LaserScan
<std::allocator > >&’
75 | operator()(_Tp* __ptr) const
| ^~~~~~~~
···

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

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

到:

void ScanCallback(const sensor_msgs::msg::LaserScan::ConstSharedPtr scan);
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值