终止内务管理是什么意思

what does termination housekeeping mean?

本文关键字:是什么 意思 管理 终止      更新时间:2023-10-16

"终止内务管理"一词是什么意思?我读过析构函数用于对类的对象执行终止内务处理。我不知道这是什么意思。

谢谢。

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

如果要在系统回收对象的存储之前执行某些操作,请在析构函数中编写代码。

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

让我们从这里举一个例子:

#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;
}

你可以在这里看到另一个例子。