AgentSkillsCN

m14-mental-model

C++ 心智模型:指针 vs 引用、初始化、未定义行为。

SKILL.md
--- frontmatter
name: m14-mental-model
description: "C++ Mental Models: Pointer vs Reference, Initialization, Undefined Behavior."

C++ Mental Models

Core Question

What happens in memory?

  • Value: Does it own the bytes?
  • Reference: Is it an alias?
  • Pointer: Is it nullable?

Thinking Prompt

  1. Is it a Copy or Reference?

    • auto x = y (Copy).
    • auto& x = y (Reference).
  2. Does it dangle?

    • Returning &local is always wrong.

Quick Reference

ConceptMental Model
T&Guaranteed Alias.
T*Nullable Address (Requires check).
std::moveCast to rvalue (Prepare to steal).