Difficulty: 🟡 Medium
Category: C++ for ROS2
Tags: cpp, smart-pointers, memory, modern-cpp
Execution Type: basic_python
Seen at: Boston Dynamics, NVIDIA
Frequency: medium
C++ is the standard for performance-critical robotics (drivers, control loops, SLAM). Smart pointers (std::shared_ptr, std::unique_ptr) prevent memory leaks, which is critical for robots that run for weeks without restarting.
Create a minimal C++ ROS2 node using modern C++ features like smart pointers (std::shared_ptr).
- Language: C++
- Create a class inheriting from
rclcpp::Node - Node name:
cpp_smart_node - Use
RCLCPP_INFOto log "C++ Node Started" in the constructor - Ensure standard main function with
rclcpp::init,rclcpp::spin,rclcpp::shutdown
Output:
- Console Log: "C++ Node Started"
- Compilation errors due to missing semicolons or headers.
- Forgetting
publicinheritance:class MyNode : public rclcpp::Node
- Smart pointers: shared_ptr and unique_ptr used
- Memory management: No memory leaks
- Lambda callbacks: Modern C++ syntax
- Problem #8
Found an issue with this problem's description, or have a better hint?
Open a PR or report it in Discussions.
Note: TestScripts and reference solutions are maintained by the SimuCode team
and are not part of this open spec. This ensures grading integrity on simucode.online.