ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A

ROS2 Node Definition in Class

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

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;
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_07_fastrtps\ros2-windows\include\rclcpp/function_traits.hpp(52): error C2825: ‘FunctionT’: must be a class or namespace when followed by ‘::’ [D:\sr

can anyone help me! Thanks in advance.

Please ask on with the appropriate tags like ros2, and then include more details, like the OS you’re using, the compiler version you’re using, which version of ROS 2 you’re using, and how you installed ROS 2.