ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You're close! First, the template typenames T and ServiceT are the same types, so you only need to declare one, let's use ServiceT.

You did not specify why "the second parameter does not work", so it's impossible to know for sure what your issue is... The following could work:

template <typename ServiceT>
bool sendRequest(std::shared_ptr<rclcpp::Client<ServiceT>> client, std::shared_ptr<typename ServiceT::Request> request)
{
    // let 'node' be a std::shared_ptr<NodeType> declared elsewhere...
    auto result = client->async_send_request(request);
    return rclcpp::FutureReturnCode::SUCCESS == rclcpp::spin_until_future_complete(node, result);
}

The difference for the second argument is the typename keyword. Since this is a templated function, the compiler needs to know that for any ServiceT, that ServiceT::Request will be a type name. Without the typename keyword, the compiler doesn't have enough information to know your intention, e.g. ServiceT::Request could be a static data member.

In the future, you should at least include why "the second parameter does not work".