m02-resource/SKILL.md
Mastering C++ Smart Pointers: unique_ptr, shared_ptr, weak_ptr. Triggers: memory management, cycles, enable_shared_from_this, make_unique, make_shared, custom deleters.
npx skillsauth add 13eholder/modern-cpp-skills m02-resourceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
How many owners does this resource to have?
std::unique_ptr (90% of cases).std::shared_ptr.std::weak_ptr.| Issue | Design Question |
| ------------------------ | ---------------------------------------------------------------- |
| Memory Leak (Cycles) | Do you have shared_ptr pointing to each other? Cycle = Leak. |
| Dangling Pointer | Did you store a weak_ptr or raw pointer but check it too late? |
| Double Free | Did you make two unique_ptrs from one raw pointer? |
| Performance | Are you copying shared_ptr unnecessarily? (Atomic ops). |
Can I use unique_ptr?
std::move).Is this a Cycle?
shared_ptr).weak_ptr).shared_ptr to Parent, they never die.Do I need a custom deleter?
FILE*, SDL_Surface*)?unique_ptr<FILE, DeclType(&fclose)> handles this perfectly.Trace Up:
shared_ptr cycle. The reachable memory is technically "owned", just mutually.weak_ptr.Trace Down:
std::vector<std::unique_ptr<Base>>| Pattern | Cost | Use When |
| ----------------------------- | ------------- | ------------------------------------------------- |
| make_unique | Zero | Creating new heap objects. |
| make_shared | 1 Alloc | Creating access-controlled shared objects. |
| weak_ptr | Control Block | Breaking cycles, Caching. |
| enable_shared_from_this | Zero | Need shared_from_this() inside member function. |
tools
Common C++ Anti-Patterns. Triggers: global variables, new/delete, C-style cast, macros, void*.
data-ai
C++ Mental Models: Pointer vs Reference, Initialization, Undefined Behavior.
data-ai
Mastering C++ Domain Errors: Exception Hierarchies, System Errors, and Expected.
data-ai
Mastering C++ Lifecycle: RAII, Destructors, Static Initialization, Rule of 5.