#include#include int main() { boost::scoped_ptr p{new int{42}}; std::cout << *p << std::endl; // prints 42 return 0; }
#includeIn this example, we create a boost scoped_ptr to an integer and initialize it with the value 42. We then check if the pointer is still valid and print the value of the integer. We then reset the pointer with the value 74 and print the new value. Boost scoped_ptr is part of the Boost C++ Libraries package.#include int main() { boost::scoped_ptr p{new int{42}}; if (p) { std::cout << *p << std::endl; // prints 42 } p.reset(new int{74}); std::cout << *p << std::endl; // prints 74 return 0; }