Ask Your Question

[ROS2] Making rclcpp::Publisher a template class [closed]

asked 2019-07-11 14:05:49 -0600

ahtsan gravatar image

Is it possible to do that? Like

template <typename T>
class CustomerPublisher : public rclcpp::Node
   typename rclcpp::Publisher<T>::SharedPtr publisher_;

I tried it and instantiate a CustomerPublisher<std_msgs::msg::String>. It is able to compile, but got the following error

...undefined reference to `CustomerPublisher<std_msgs::msg::String_<std::allocator<void> > >::publish(std_msgs::msg::String_<std::allocator<void> >)'
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by ahtsan
close date 2019-07-16 14:54:03.007506

1 Answer

Sort by ยป oldest newest most voted

answered 2019-07-11 18:37:01 -0600

ahtsan gravatar image

Answering myself: Do the function definition in .hpp works.

edit flag offensive delete link more

Question Tools



Asked: 2019-07-11 14:05:49 -0600

Seen: 104 times

Last updated: Jul 11 '19