m01-ownership

Guide C++ ownership decisions using RAII, smart pointers, and non-owning references.

14|3|Updated Jan 25, 2026
One-click install
npx skills add https://github.com/13eholder/Modern-Cpp-Skills --skill m01-ownership-13eholder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: m01-ownership
Source: https://github.com/13eholder/Modern-Cpp-Skills/tree/main/m01-ownership
Command: npx skills add https://github.com/13eholder/Modern-Cpp-Skills --skill m01-ownership-13eholder

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Ownership and lifetime decisions in C++ are error-prone; this skill guides proper use of RAII, smart pointers, and non-owning references to prevent common defects.

Core Features & Use Cases

  • Guidance on when to transfer ownership vs share ownership, including usage of std::unique_ptr, std::shared_ptr, raw pointers, and references.
  • Best practices to avoid common pitfalls such as double frees, use-after-free, and memory leaks through clear lifetime management.
  • Real-world scenarios spanning small utilities to large codebases to standardize ownership patterns.

Quick Start

Ask the AI to review a resource ownership scenario and propose the appropriate ownership strategy using RAII and smart pointers.

Frequently Asked Questions about m01-ownership

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I decide between using std::unique_ptr and std::shared_ptr for C++ ownership?

To decide between std::unique_ptr and std::shared_ptr for C++ ownership, use unique_ptr for exclusive ownership and shared_ptr when multiple parts of your codebase need shared access. This skill guides proper RAII selection.

What is the best way to avoid use-after-free and double free errors in C++?

The best way to avoid use-after-free and double free errors in C++ is by applying RAII and move semantics with smart pointers. This skill provides guidance on clear lifetime management to prevent these common defects.

How does RAII help with memory safety and resource management in C++?

RAII ensures memory safety in C++ by binding resource lifetimes to object scopes, automatically releasing resources when objects go out of scope. This skill helps standardize ownership patterns using stack objects and smart pointers.

When should I use raw pointers and non-owning references instead of smart pointers?

Use raw pointers and non-owning references in C++ when you need to observe or access an object without taking ownership. This skill guides correct usage of non-owning references alongside std::unique_ptr and std::shared_ptr.

Can this ownership guidance apply to large C++ codebases?

Yes, this guidance applies to large C++ codebases. It covers real-world scenarios spanning small utilities to large codebases, helping standardize ownership patterns and resource management strategies across varying project scales.

Why does transferring ownership with move semantics prevent memory leaks?

Transferring ownership with move semantics prevents memory leaks by ensuring a single owner takes responsibility for the resource at any given time without copying. This skill guides correct move semantics application to avoid leaks.