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_07_fastrtps\ros2-windows\include\rclcpp/function_traits.hpp(52): error C2825: ‘FunctionT’: must be a class or namespace when followed by ‘::’ [D:\sr
c\ros2_pub_sub_test\build\ros2_pub_sub_test\listener_1.vcxproj]
can anyone help me! Thanks in advance.