Zest.

C++: Smart pointers

A short, tested C++ example for smart pointers. Copy it and adjust the names and paths for your project.

C++
#include <memory>

auto p = std::make_unique<Widget>(42);      // sole owner
auto s = std::make_shared<Widget>(42);      // shared ownership
std::shared_ptr<Widget> t = s;              // count is now 2

Find it in Zest

Search for “cpp smart pointers” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More C++ examples

All C++ examples