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 and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 10 : 36
Notes about C++
Abstraction Mechanisms, Part 1
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

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-1/point.hClass Point - with a pointer representation .


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-1/point.ccImplementation of class point - with an insufficient destructor .


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-1/prog.ccA sample program with memory leaks.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-2/point.hClass Point - with a pointer representation - same as before.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-2/point.ccImplementation of class point - now with a destructor that deallocates the Point representation.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-2/prog.ccA sample program - now without memory leaks.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors-2/program-outputOutput from the program.


Go to exercisePoint 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