#includeint main() { std::shared_ptr ptr(new int(42)); return 0; }
#includeint main() { std::shared_ptr ptr1(new int(42)); std::shared_ptr ptr2 = ptr1; return 0; }
#includeIn this example, we create a shared_ptr called ptr1 that points to an integer. We then create a new shared_ptr called ptr2 and assign it to ptr1. We then reset ptr1, which means that ptr1 no longer owns the integer, but ptr2 still does. The std::shared_ptr is part of the C++ Standard Library.int main() { std::shared_ptr ptr1(new int(42)); std::shared_ptr ptr2 = ptr1; ptr1.reset(); return 0; }