Objects can have constructors and destructors. Thus, while you cannot use a valid variable, you can rely on code that runs in the constructor or destructor.
A good example of this is std::lock_guard
, which uses a destructor to unlock the mutex when the lock goes out of scope.
source
to share