# include# include using namespace std::tr1; int main() { shared_ptr p1(new int(42)); std::cout << *p1 << std::endl; return 0; }
# includeIn the above code, we create a shared pointer `p1` which points to an integer with a value of 42. We also provide a custom deleter function `deleter` to delete the memory pointed to, which prints a message while doing so. The `std::tr1::shared_ptr` implementation belongs to the TR1 library, which is a part of the C++ Standard Library.# include using namespace std::tr1; void deleter(int* p) { std::cout << "deleting memory at " << p << std::endl; delete p; } int main() { shared_ptr p1(new int(42), deleter); return 0; }