Lecture overview -- Keyboard shortcut: 'u'  Previous page: Use of constructors -- Keyboard shortcut: 'p'  Next page: A class that needs a destructor -- 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 9 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Destructors

Destructors are essential for resource management purposes in C++

Most classes do not need destructors

Destructors are called implicitly

  • The C++ Programming Language: Page 242, 244.
 

  • Destructor activation:

    • When an automatic variable of class type goes out of scope

      • Because of normal termination

      • Because of exceptional termination - stack unwinding

    • When a dynamically allocated object is explicitly deleted from the free store (the heap)

      • With delete or delete[]

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


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors/point.ccImplementation of the destructor that reveal its activation.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors/prog2.ccIllustration of destructor activation when automatic variables go out of scope .


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/destructors/program-outputActual program output.