Well designed value types created with C++ classes use scope based management of their resources.
-
Any resources acquired by the class during its construction or invocation of other member functions is returned by its destructor.
-
C++ conspires to automatically destroy all instances of types declared in any scope when the thread of execution leaves that scope.
-
That means that the C++ language provides you the means to make your classes entirely responsible for managing their own resources.
Users of the class don't have to know anything or remember anything to support that. They simply declare instances of the class
in the scope where they need it and allocation and deallocation happen automatically.
If users need more persistant life time, they get a pointer to an instance of your class on the heap by using the new operator;
and when they have finished with the object, destroy it by calling delete on the pointer.