using std::placeholders::_1;
class MinimalSubscriber
{
public:
MinimalSubscriber() {}
init(int m_agrc, char** m_argv)
{
rclcpp::init(m_argc, m_argv);
m_rosnode = std::make_shared\<rclcpp::Node>("node_sub");
sub = m_rosnode->create_subscription<std_msgs::msg::String>( "topic",
std::bind(&MinimalSubscriber::topic_callback, this, _1));
while(rclcpp::ok())
{
rclp::spin(m_rosnode);
}
}
private:
void topic_callback(const std_msgs::msg::String::SharedPtr & msg)
{
RCLCPP_INFO(m_rosnode->get_logger(), "I heard: '%s'", msg->data.c_str())
}
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr m_rosnode;
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
std::shared_ptr<MinimalSubscriber> m_sub = std::make_shared<MinimalSubscriber>;
rclcpp::shutdown();
return 0;
}
Hi I tried to build this above example, but I got an error:
error C2672: 'rclcpp::AnySubscriptionCallback<MessageT,Alloc>::set': no matching overloaded function found.
this error was caused by this line :
_subscription_ = m_rosnode->create_subscription<std_msgs::msg::String>( "topic", std::bind(&MinimalSubscriber::topic_callback, this, _1));
Can anyone help me? Thanks in advance!