Class destructors
A class destructor is called when the class instance is de-allocated
- If the class was allocated with new,
when delete is called, and
- If allocated on the runtime stack (introduced in a block of statements),
when the identifier goes out of scope.
#include <iostream>
classs Point {
public:
int x, y;
Point(void) {
cout << "constructor invoked" << endl;
}
~Point(void) {
cout << "destructor invoked" << endl;
}
}
|
CITS2002 Systems Programming, Lecture 23, p12, 17th October 2023.
|