Monday, May 16, 2011

Use templates to prevent memory leakage

Make a class template to create an instance of a desired class and in the destructor of the class template, delete the item the pointer points to. In this way, the programmer won't have to worry about freeing the memory.