::SharedPtr vs std::shared_ptr<>
Hello,
Please bear with me, I haven´t been programming since 2006, and it turns out that learning both c++11/c++17 and ROS2 has a bit of a steep learning curve. ;-)
After reading the relevant chapters at learncpp.com, I think I have an adequate understanding of std::shared_ptr, weak_ptr and unique_ptr.
However, going back to the ROS2 tutorials, I see that often an alias is defined:
using something::SharedPtr = std::shared_ptr<something>
For instance, in the publisher tutorial, the publisher is declared as follows:
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
which (I think) is fully equivalent to:
std::shared_ptr<clcpp::Publisher<std_msgs::msg::String>> publisher_;
I find this rather confusing, even more so since it is not general. For instance, in the TF2 TransformBroadcaster tutorial, the broadcaster must be declared as follows:
std::shared_ptr<tf2_ros::StaticTransformBroadcaster> tf_static_broadcaster_;
since the ::SharedPtr alias is not defined:
tf2_ros::StaticTransformBroadcaster::SharedPtr tf_static_broadcaster_;
// Not ok: "class tf2_ros::StaticTransformBroadcaster has no member SharedPtr"
So: is there any specific reason (other than it being 6 characters less) to give preference to the ::SharedPtr
way of declaring, or is it ok to stick to using std::shared_ptr<...>
?