When programming with C++, you usually meet a pair of acquire/release resources (memory, file, mutex, etc) or a pair of change/restore state (or setting). For examples:
The resource will be leaked, the state won’t restore if:
Someone (maybe you) accidentally exits the function between the pair.
There is an exception between the pair. Then the code is not exception safe.
Because the destructor will be called when an object is destroyed, we can use it to release the resource automatically. This object is called scoped object.
By using scoped object, you can prevent resource leak, the code is less error-prone and exception safe. Using it widely in your project is a good habit.
P/S: Smart pointer is a kind of scoped object. std::unique_ptr, std::shared_ptr and std::weak_ptr are smart pointers in C++11.