【发布时间】:2016-02-09 10:32:20
【问题描述】:
我想在类中使用 std::atexit 函数来清理异常终止。 我正在类构造函数中注册函数句柄,但出现错误。 (codetest.cpp:12:25:错误:非静态成员函数的使用无效) 这是我的简单理解代码(其他是一个大项目,应用程序在一些致命错误时退出,但我需要清理 mu 类的一些属性)
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
class cleanUP
{
public:
cleanUP ()
{
atexit (atexit_handler);
}
~cleanUP()
{
}
void atexit_handler ()
{
// Will cleanup some temp files and malloc things.
cout << "Call atexit" <<endl;
}
};
int main () {
cleanUP cleanup;
}
还有其他好的清理方法吗? 谢谢。
【问题讨论】:
标签: c++