#include#include int main() { std::shared_ptr p(new int(5)); std::cout << "Value of p: " << *p << std::endl; return 0; }
#includeIn this example, shared_ptr is used to manage the memory allocation of an integer object passed as an argument to function(). The shared_ptr constructor is called with a new integer object as an argument and returns a smart pointer object p. The smart pointer object is passed as an argument to the function, which can access the integer object. The shared_ptr is part of the C++11 standard library and is included in the#include void function(std::shared_ptr p) { std::cout << "Value of p: " << *p << std::endl; } int main() { std::shared_ptr p(new int(5)); function(p); return 0; }