终止管家是什么意思?

what does termination housekeeping mean?

表达式"termination housekeeping"是什么意思?? 我读过析构函数用于对 class 的对象执行终止内务处理。不知道什么意思

谢谢。

在析构函数的上下文中,终止内务处理是在对象要被销毁之前完成的工作。

如果你想在系统回收对象存储之前做一些事情,把代码写在析构函数中。

比如初学者用它来理解构造函数和析构函数的调用顺序。

让我们举一个来自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;
}

你可以看另一个例子here