docs(cpp): 补全引用基础练习答案 - #211
Merged
Charliechen114514 merged 1 commit intoSep 5, 2026
Merged
Conversation
Charliechen114514
approved these changes
Sep 5, 2026
| int height_{}; | ||
|
|
||
| public: | ||
| Config& set_width(int width) |
Member
There was a problem hiding this comment.
嗯嗯,写的很好,这个后面bro学习设计模式的时候,Builder模式的链条形式就是这样的,到时候我的ZerOS——一个玩具的C++23的RTOS的TCB控制块构建就是这样处理的
Charliechen114514
merged commit Sep 5, 2026
903bdc1
into
Awesome-Embedded-Learning-Studio:main
5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
本 PR 为第一卷第 4 章《03-references:引用》的三道练习题补全参考答案,是练习答案补全系列(##201、##203、##206、##207)的延续。答案统一放在 VitePress
::: details折叠块内,默认收起,不干扰正文阅读;读者做完题后可展开对照。主要变更
✅ 完成内容
练习一:用引用修改数组
std::array<int, 5>&传参,替代无法保留长度信息的 C 风格数组g++ -std=c++17 -Wall -Wextra)与实测运行结果练习二:找错(悬空引用辨析)
int& r = get_value();)本身可以编译,通过它读写才是 UB——与题目"二分法"表述的差异单独用一段说明get_value、声明时必须初始化引用、传入具名左值代替字面量练习三:链式配置器
Config类两个 setter 均返回Config&,成员用int width_{} / int height_{}就地初始化c.set_width(800).set_height(600);链式调用📝 技术亮点
std::cout << r;)-Wall -Wextra零警告通过📄 变更文件
documents/vol1-fundamentals/ch04/03-references.md(+137 / −4)
其中 −4 行为练习二题干代码的行号标注修正:原 A/B/C 三处注释顺延为 A/B/C/D,与新增解析一一对应。
测试
本机环境:Windows 10 x64 + MinGW-w64 GCC 8.1.0
g++ -std=c++17 -Wall -Wextra ex1.cpp -o ex1 && ./ex1编译运行,输出与文中一致(零警告)[-Wreturn-local-addr]/[-Wunused-variable]警告,与解析结论一致-Wall -Wextra零警告markdownlint documents/vol1-fundamentals/ch04/03-references.md通过.venvPython 运行scripts/validate_frontmatter.py:991 个文件全部通过,0 错误::: details ... :::折叠块配对正确,VitePress 渲染无异常后续计划
ch04 尚有两篇文章的练习未补答案,计划后续 PR 继续:
02-pointer-arithmetic.md(3 道练习)04-smart-ptr-preview.md(2 道练习)相关 Issue
无(练习答案补全系列任务)