Lecture overview -- Keyboard shortcut: 'u'  Previous page: Destructors -- Keyboard shortcut: 'p'  Next page: Resource acquisition is initialization - RAII -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Alphabetic index  Help page about these notes  Course home    Abstraction Mechanisms, Part 1 - slide 10 : 36

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 - with a pointer representation .
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