Manage a Resource with Smart Pointers
Choose C++ ownership for one small resource and show safe access and automatic cleanup on normal and exceptional exits.
Write a small C++ example using smart pointers.
For this exercise, assume a local client acquires one neutral Resource whose read operation returns its label. The client uses it once and then leaves the owning scope. Demonstrate both a normal exit and an operation that throws after acquisition.
In each run, create one Resource and release it automatically exactly once. Use a small construction/destruction counter or log to make that outcome visible.
Choose an appropriate standard C++ smart pointer and explain its ownership. You may choose unique or shared ownership if your code and explanation agree. Keep any borrowed access inside the lifetime of the owner; do not access the resource after it is released. Do not use a raw pointer as an owning handle.
Propose the objects, public contracts and lifetime rules, then write the central C++ code and a short demonstration. No network, filesystem, user interface, persistence or concurrency is needed.
The Resource fixture, exit cases and counters are authored practice assumptions because the original code example was not preserved.