Skip to content

no matching function for rclcpp::create_publisher #1876

@alsora

Description

@alsora

Bug report

Build errors when calling rclcpp::create_publisher are not easy to solve looking at the create_publisher.hpp file.
Either we should add documentation there, or we should make the functions more flexible in the accepted input arguments.

Required Info:

  • Operating System:
    • Ubuntu 20.04
  • Installation type:
    • binaries
  • Version or commit hash:
    • Rolling
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

class MyNode : public rclcpp::Node
{
public:
    MyNode() : rclcpp::Node("my_node")
    {
        auto pub = rclcpp::create_publisher<std_msgs::msg::String>(
            this->get_node_topics_interface(),
            "my_topic",
             rclcpp::SensorDataQoS());
    }
};

Actual behavior

The above code snippet fails to compile due to no matching function found in rclcpp::create_publisher.
Looking at https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/create_publisher.hpp didn't really help to figure out the solution to the problem.

Tried also to add a this->get_node_parameters_interface() argument to match the signatures there, but got again errors

        auto pub = rclcpp::create_publisher<std_msgs::msg::String>(
            this->get_node_parameters_interface(),
            this->get_node_topics_interface(),
            "my_topic",
             rclcpp::SensorDataQoS());

The following syntax works

       auto node_topics_interface = this->get_node_topics_interface();
       auto pub = rclcpp::create_publisher<std_msgs::msg::String>(
            node_topics_interface,
            "my_topic",
             rclcpp::SensorDataQoS());

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions