#include#include int main() { std::shared_ptr mySharedPtr(new int(10)); std::cout << "Value of mySharedPtr: " << *mySharedPtr << std::endl; return 0; }
#includeIn the above examples, we are using the std::shared_ptr class provided by the C++ standard library. Hence, the package library for these examples is the C++ standard library.#include struct Person { std::string name; int age; }; int main() { std::shared_ptr p1(new Person{"John", 30}); std::shared_ptr p2 = p1; std::shared_ptr p3 = p1; std::cout << "p1's name: " << p1->name << ", age: " << p1->age << std::endl; std::cout << "p2's name: " << p2->name << ", age: " << p2->age << std::endl; std::cout << "p3's name: " << p3->name << ", age: " << p3->age << std::endl; return 0; }