You already know Introductory and Easy. Medium assumes those habits and asks for sharper tools.
C++ Medium · Lesson 1 · On the house
unique_ptr
One owner. Lesson 1 is free — on the house.
Lessons · C++ Medium · Lesson 1 of 10 · On the house
unique_ptr
One owner.

std::unique_ptr
auto p = std::make_unique
release() yields the raw pointer and gives up ownership (you become responsible). reset() deletes the current object (or replaces it). get() borrows the raw pointer without releasing ownership — don't delete what get() returns. Ownership is the plot of modern C++. Ask who creates the object, who may use it, and who destroys it. If you can't answer, you're guessing — and guessing with pointers is how undefined behavior sneaks in. Move is not magic copy — it transfers resources. After a move, treat the source as empty-but-valid unless you know better. That mental model prevents use-after-move bugs. Before you build, predict what unique_ptr should do on the still's inputs. Prediction turns compiling into confirmation.
unique_ptr is the default choice for heap ownership in modern C++. Shared ownership is rarer than people think — try unique first. Arrays have unique_ptr<T[]> specialization; prefer vector for most sequences anyway. Zero-based indexing is the tax you pay once and forever. When something looks one-off, count from zero on paper before you blame the standard library. Ownership is the plot of modern C++. Ask who creates the object, who may use it, and who destroys it. If you can't answer, you're guessing — and guessing with pointers is how undefined behavior sneaks in. Before you build, predict what unique_ptr should do on the still's inputs. Prediction turns compiling into confirmation.
Custom deleters exist for non-new resources (FILE*, handles). The still uses the default deleter for a single int. Ownership plot: who creates, who destroys — unique_ptr answers “this object destroys it.” Ownership is the plot of modern C++. Ask who creates the object, who may use it, and who destroys it. If you can't answer, you're guessing — and guessing with pointers is how undefined behavior sneaks in. Move is not magic copy — it transfers resources. After a move, treat the source as empty-but-valid unless you know better. That mental model prevents use-after-move bugs. Before you build, predict what unique_ptr should do on the still's inputs. Prediction turns compiling into confirmation.
Don't mix raw owning new with unique_ptr casually. Once it's in a unique_ptr, let the smart pointer finish the job. Double-delete and leaks are what we're ending. When the compiler or runtime complains, read the first error first — later errors are often fallout. Change one thing. Rebuild. That calm loop beats rewriting the whole file from memory. Zero-based indexing is the tax you pay once and forever. When something looks one-off, count from zero on paper before you blame the standard library. Before you build, predict what unique_ptr should do on the still's inputs. Prediction turns compiling into confirmation.
Put unique_ptr in a sentence you could teach a friend: what changes in the program, what stays the same, and what you expect when you build and run the still. Zero-based indexing is the tax you pay once and forever. When something looks one-off, count from zero on paper before you blame the standard library. Ownership is the plot of modern C++. Ask who creates the object, who may use it, and who destroys it. If you can't answer, you're guessing — and guessing with pointers is how undefined behavior sneaks in. Before you build, predict what unique_ptr should do on the still's inputs. Prediction turns compiling into confirmation.
up
#include <memory>
auto p = std::make_unique<int>(3);make_unique
Pitfalls: copying unique_ptr (illegal); deleting get(); using release() and forgetting; shared_ptr by default out of habit; make_unique unavailable on ancient dialects — use C++14+. One owner, clear lifetime.
Quiz
What does unique_ptr represent?
Quiz
Why prefer make_unique?
Quiz
Can you copy a unique_ptr?
Quiz
What happens when a unique_ptr is destroyed?
Quiz
What does get() return?
Quiz
Which header provides unique_ptr?
Check
Match the still for: unique_ptr.
One owner is the default story. Next: shared_ptr — shared ownership, used sparingly.
Open-book: the answers are on this page. Pass every quiz and check (7) to mark the lesson done. This visit: 0/7.