Bridge 1 to 2

#include <iostream>

// include ROS 1
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-parameter"
#endif
#include "ros/ros.h"
#include "std_msgs/String.h"
#ifdef __clang__
# pragma clang diagnostic pop
#endif

// include ROS 2
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

//create a publisher
rclcpp::publisher::Publisher<std_msgs::msg::String>::SharedPtr pub;

void chatterCallback(const std_msgs::String::ConstPtr & ros1_msg)
{
  // print heard message
  std::cout << "I heard: [" << ros1_msg->data << "]" << std::endl;
  // create ros2_msg variable
  auto ros2_msg = std::make_shared<std_msgs::msg::String>();
  // save ROS 1 into ROS 2 variable
  ros2_msg->data = ros1_msg->data;
  // print
  std::cout << "Passing along: [" << ros2_msg->data << "]" << std::endl;
  // publish ROS 2 message
  pub->publish(ros2_msg);
}

int main(int argc, char * argv[])
{
  // ROS 2 node and publisher
  rclcpp::init(argc, argv);
  auto node = rclcpp::node::Node::make_shared("talker");
  pub = node->create_publisher<std_msgs::msg::String>("chatter", rmw_qos_profile_sensor_data);

  // ROS 1 node and subscriber
  ros::init(argc, argv, "listener");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("chatter", 10, chatterCallback);

  ros::spin();

  return 0;
}