Values & References14 / 16
Up next

unique_ptr owns the heap

#include <print>
#include <memory>

int main() {
    // unique_ptr owns a heap int and frees it when it goes out of scope
    auto boxed = std::make_unique<int>(42);
    *boxed += 1;
    std::println("{}", *boxed);
}
What you're solving

one owner, freed automatically