[ros-users] [Discourse.ros.org] [Next Generation ROS] ROS2 …

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Changsong Yu via ros-users
Date:  
To: ros-users
CC: Changsong Yu
Subject: [ros-users] [Discourse.ros.org] [Next Generation ROS] ROS2 Subscriber defined in Class


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!





---
[Visit Topic](https://discourse.ros.org/t/ros2-subscriber-defined-in-class/4863/1) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list

http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>