[ros-users] [Discourse.ros.org] [Next Generation ROS] ROS2 Node Definition in Class

Changsong Yu ros.discourse at gmail.com
Fri May 18 13:01:47 UTC 2018



class Listener
{
public:
  Listener()
  {
	  m_rosNode = rclcpp::Node::make_shared("Listener");
	  sub_  = m_rosNode->create_subscription<std_msgs::msg::String>("chatter", &Listener::callback);
	  rclcpp::spin(m_rosNode);
  }
  void callback(const std_msgs::msg::String::SharedPtr msg)
  {
	  RCLCPP_INFO(m_rosNode->get_logger(), "I heard: [%s]", msg->data.c_str());
  }

private:
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr sub_;
  std::shared_ptr\<rclcpp::Node\>  m_rosNode;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  Listener lister;
  rclcpp::shutdown();
  return 0;
}

Hi I am a beginner, I wrote some codes described above. However, after ament build, it comes out an error:
     5>C:\dev\ros2_2018_03_27_fastrtps\ros2-windows\include\rclcpp/function_traits.hpp(52): error C2825: 'FunctionT': must be a class or namespace when followed by '::' [D:\Repo\pj-dc_int\dc_fw\sr
       c\ros2_pub_sub_test\build\ros2_pub_sub_test\listener_1.vcxproj]

can anyone help me! Thanks in advance.





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




More information about the ros-users mailing list