Lecture 4 - Slide 12 : 40
A class that needs a destructor

An example where it is necessary to program a destructor

For sake of the example we introduce a dynamically allocated representation of points

point.h
Class Point - representated as a dynamically allocated array of two doubles .
point.cc
Implementation of class point - with an insufficient destructor .
prog.cc
A sample program with memory leaks.
point.h
Class Point - with a pointer representation - same as before.
point.cc
Implementation of class point - now with a destructor that deallocates the Point representation.
prog.cc
A sample program - now without memory leaks.
program-output
Output from the program.
Go to exercise
Point destruction - now with a problematic point copy constructor

If an object o allocates resources when constructed - or during its life time - o's destructor is responsible for relinquishing these resources when o is deleted or goes out of scope

If o does not allocate such resources, its destructor is typcially not programmed