Is it possible for dynamically allocated objects to be automatically deleted when you exit out of scope?
1
Expert's answer
2010-08-04T11:10:56-0400
Technically, it is possible, but you will have to use tricks. You have to create a class that will encapsulate the dynamic object. In constructor you allocate memory for it, and in destructor you free it. If this object is non-trivial class and you want to be able to use the methods of this class via the class member's selector, you can overload the operator “->” and make sure that it returns an encapsulated pointer.
Comments
Leave a comment