#include #include class Resource { public: Resource() { std::cout << "Resource acquired\n"; } ~Resource() { std::cout << "Resource deleted\n"; } void use() { std::cout<<"Resource use\n"; } }; void test() { // allocate memory from the heap: auto res = std::make_unique(); // One way // std::unique_ptr res{new Resource()}; // Another way std::cout<<"test using Resourse\n"; res->use(); std::cout<<"about to exit test()\n"; }// smart pointer automatically deleted here int main() { std::cout<<"calling test()\n"; test(); std::cout<<"returned from test()\n"; }