What does the expression "termination housekeeping" mean ?? I've read that destructors are used to perform termination housekeeping on an object of a class. I don't know what does it means.
Thanks.
In context of destructors, termination housekeeping is the work to be done just before an object is to be destroyed.
If you want to do something before the system reclaims the object's storage, write the code in destructor.
For example, beginners use it to understand the sequence of constructors and destructors being called.
Lets take an example from here:
#include <iostream>
using namespace std;
class Line {
public:
void setLength( double len );
double getLength( void );
Line(); // This is the constructor declaration
~Line(); // This is the destructor: declaration
private:
double length;
};
// Member functions definitions including constructor
Line::Line(void) {
cout << "Object is being created" << endl;
}
Line::~Line(void) {
// THE PLACE FOR TERMINATION HOUSEKEEPING
cout << "Object is being deleted" << endl;
}
void Line::setLength( double len ) {
length = len;
}
double Line::getLength( void ) {
return length;
}
// Main function for the program
int main( ) {
Line line;
// set line length
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
return 0;
}
You can see another example here.