adambard / adambard/learnxinyminutes-docs
[c++] std::shared_ptr circular reference example incorrect?
- 主要语言
- Markdown
- 星标
- 12.3k
- 派生
- 3.7k
- 平均合并
- 13 小时 10 分钟
- 30 天内合并 PR
- 6
描述
https://learnxinyminutes.com/docs/c++/
I do not think the example creates or exemplifies circular pointers.
```
// Beware of possible circular references!!!
// There will be always a reference, so it will be never destroyed!
std::shared_ptr doggo_one(new Dog());
std::shared_ptr doggo_two(new Dog());
doggo_one = doggo_two; // p1 references p2
doggo_two = doggo_one; // p2 references p1
```
The `doggo_one`/`doggo_two` manipulation just looks like it changes which `Dog` instance the smart pointers refers to, without creating any cycles.
I do not know C++ (that's why I'm here) but my guess is that circular (smart) pointers would require, e.g., that each `Dog` object to contain a `std::shared_ptr` to the other `Dog` object.
贡献指南
调研方向
Start from the C++ page linked in the issue and inspect the shown std::shared_ptr circular-reference example. Verify whether the two pointer assignments actually create a cycle, then update the documentation so the warning and example match. Done means the C++ docs no longer present an incorrect circular reference example.
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100