Use friend property to hide impl function#29
Conversation
Walkthrough此拉取请求引入了对多个C++头文件的访问控制和友元声明修改,为Movable类添加了对Armor、Posture和Transform结构体的私有成员访问权限。同时在CMakeLists.txt中注释掉了显式的Ceres依赖查找调用。 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@CMakeLists.txt`:
- Line 14: The commented out change to the CMake dependency (the line containing
find_package(Ceres REQUIRED)) is unrelated to the PR topic and should be removed
or isolated; either restore the original find_package(Ceres REQUIRED) line in
CMakeLists.txt or move this change into its own commit/PR with a clear rationale
so the current PR remains focused on the friend/impl function visibility
changes.
| find_package(OpenCV 4.5 REQUIRED) | ||
| find_package(OpenVINO REQUIRED) | ||
| find_package(Ceres REQUIRED) | ||
| # find_package(Ceres REQUIRED) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for Ceres includes and namespace usage
echo "=== Searching for Ceres includes ==="
rg -i 'include.*ceres' --type=cpp --type=c --type=h
echo -e "\n=== Searching for ceres:: namespace usage ==="
rg 'ceres::' --type=cpp --type=c --type=h
echo -e "\n=== Searching for any Ceres references ==="
rg -i 'ceres' --type=cpp --type=c --type=h -lRepository: Alliance-Algorithm/rmcs_auto_aim_v2
Length of output: 206
注释掉 Ceres 依赖与 PR 主题(friend 隐藏 impl 函数)无关。
此更改虽然安全且有效(项目代码中未使用 Ceres),但与 PR 的主要目标无关,建议拆分到单独的提交或 PR 中。
🤖 Prompt for AI Agents
In `@CMakeLists.txt` at line 14, The commented out change to the CMake dependency
(the line containing find_package(Ceres REQUIRED)) is unrelated to the PR topic
and should be removed or isolated; either restore the original
find_package(Ceres REQUIRED) line in CMakeLists.txt or move this change into its
own commit/PR with a clear rationale so the current PR remains focused on the
friend/impl function visibility changes.
Pull Request 摘要
目的
使用友元属性隐藏CRTP实现函数,使基类
Movable能够访问派生类的私有impl_move()方法。主要变更
CMakeLists.txt
find_package(Ceres REQUIRED)调用,禁用显式的Ceres依赖解析src/utility/rclcpp/visual/armor.hpp
Armor结构体中添加friend Movable;声明Movable基类访问Armor的私有成员,特别是impl_move()方法src/utility/rclcpp/visual/posture.hpp
Posture结构体中添加friend Movable;声明public:访问说明符,明确Config类型的公有地位impl_move()保持私有,由友元声明提供访问权限src/utility/rclcpp/visual/transform.hpp
Transform结构体中添加friend Movable;声明public:访问说明符,明确Config嵌套结构体的公有地位impl_move()保持私有,由友元声明提供访问权限设计意图
通过友元声明,使得
Movable基类能够调用派生类的私有impl_move()实现方法。这样用户只能通过基类公开的move()方法进行交互,而impl_move()作为实现细节保持隐藏和私有,符合CRTP设计模式的最佳实践。