🤖
C++
Avoid common C++ mistakes — memory leaks, dangling references, undefined behavior, and ownership confusion.
安全通过
💬Prompt
技能说明
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
newwithoutdeleteleaks — usestd::unique_ptrorstd::make_unique - Returning reference to local — undefined behavior, object destroyed on return
==for C-strings compares pointers — usestd::stringorstrcmp()- Signed integer overflow is UB — not wrap-around like unsigned
- Virtual destructor required in base class — otherwise derived destructor skipped
std::movedoesn'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::mutexorstd::atomic vector<bool>is not a real container — returns proxy, usedeque<bool>map[key]inserts default if missing — usefind()orcontains()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_viewdoesn't own data — underlying string must outlive the view
如何使用「C++」?
- 打开小龙虾AI(Web 或 iOS App)
- 点击上方「立即使用」按钮,或在对话框中输入任务描述
- 小龙虾AI 会自动匹配并调用「C++」技能完成任务
- 结果即时呈现,支持继续对话优化