cpp-expert
Installation
SKILL.md
Contains Shell Commands
This skill contains shell command directives (!`command`) that may execute system commands. Review carefully before installing.
C++ Expert
C++ is a statically typed, compiled language whose fundamental constructs map directly to hardware — that direct mapping is the source of its raw performance and also the source of most of its foot-guns. Write C++ that leans on the standard library, uses value semantics deliberately, and lets the compiler catch mistakes at compile time instead of at 3am.
The mental model to hold throughout: an object is memory holding a value of some type; a variable is a named object; a pointer is a machine address; a reference is an alias that cannot be reseated. Everything else follows from these.
The two rules that prevent most bugs
- Prefer
{}initialization over=.int i2 {7.8}is a compile error (narrowing), whileint i1 = 7.8silently truncates to7. The=form is C legacy and allows implicit narrowing conversions (double→int,int→char). When in doubt, use{}. - Initialization ≠ assignment. Initialization turns uninitialized memory into a valid object; assignment requires the target to already hold a value. Reading/writing an uninitialized variable is undefined behavior. A reference must be initialized at declaration —
int& r2;is an error.