目录 / C++
C++
--- name: C++ slug: cpp version: 1.0.1 description: Write safe C++ avoiding memory leaks, dangling pointers, undefined behavior, and ownership confusion. metadata: {"clawdbot":{"emoji":"⚡","requires":{"bins":["g++"]},"os":["linux","darwin","win32"]}} --- ## Quick Reference | Topic | File | |-------|------| | RAII, smart pointers, new/delete | `memory.md` | | Raw pointers, references, nullptr | `pointers.md` | | Rule of 3/5/0, inheritance, virtual | `classes.md` | | Containers, iterators, algorithms | `stl.md` | | Templates, SFINAE, concepts | `templates.md` | | Threads, mutex, atomics | `concurrency.md` | | C++11/14/17/20, move semantics | `modern.md` | | Undefined behavior traps | `ub.md` | ## Critical Rules - Raw `new` without `delete` leaks — use `std::unique_ptr` or `std::make_unique` - Returning reference to local — undefined behavior, object destroyed on return - `==` for C-strings compares pointers — use `std::string` or `strcmp()` - Signed integer overflow is UB — not wrap-around like unsigned - Virtual destructor required in base class — otherwise derived destructor skipped - `std::move` doesn't move — it casts to rvalue, enabling move semantics - Moved-from object valid but unspecified — don't use without reassigning - Data race on non-atomic is UB — use `std::mutex` or `std::atomic` - `vector<bool>` is not a real container — returns proxy, use `deque<bool>` - `map[key]` inserts default if missing — use `find()` or `contains()` to check - Braced init `{}` prevents narrowing — `int x{3.5}` errors, `int x(3.5)` truncates - Iterator invalidation on `push_back` — vector may relocate, invalidating iterators - `string_view` doesn't own data — underlying string must outlive the view
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。
存档时间线
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v5 | 2026-09-28 17:52 | 001aa811 | 已过保留期 |
| v6 | 2026-09-29 02:32 | 4320250e | 已过保留期 |
| v7 | 2026-09-28 21:28 | 001aa811 | 已过保留期 |
| v8 | 2026-09-29 12:07 | 4320250e | 已过保留期 |
| v9 | 2026-09-29 16:22 | 001aa811 | 已过保留期 |
| v10 | 2026-09-30 04:11 | 4320250e | 已过保留期 |
| v11 | 2026-09-30 11:27 | 001aa811 | 已过保留期 |
| v12 | 2026-09-30 23:34 | 4320250e | 已过保留期 |
| v13 | 2026-10-01 06:32 | 001aa811 | 已过保留期 |
| v14 | 2026-10-01 18:15 | 4320250e | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
提交举报 / 纠错
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。