ros2_controllers
ros2_controllers copied to clipboard
Use smart pointer instead of raw pointer
Modern C++ is preferred to use smart pointer instead of raw pointer for safer programming. But the current implementation is written using raw pointers e.g.:
- https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/include/hardware_interface/handle.hpp#L73
- https://github.com/ros-controls/ros2_control/blob/master/hardware_interface/include/hardware_interface/robot_hardware.hpp#L136-L138
Why don't we use the shared_ptr
and weak_ptr
instead of the raw pointers?
Do you have any real time related problem?
It may be worthwhile to also investigate whether passing pointers at all is necessary/desirable.
Afaik, pointers (smart or not) should only be passed if resource sharing or transfer of ownership is the intent. If there is no such intent, perhaps a plain (const
) reference would actually be better.
R.30: Take smart pointers as parameters only to explicitly express lifetime semantics.