析构函数不被调用

写了一个测试,验证什么时候析构函数不被调用

Mycode.cpp里

#include "stdafx.h"
#include "Mycode.h"
Mycode::Mycode()
{
    ::MessageBoxW(NULL,_T("构造函数"),0,IDOK);
};
Mycode::~Mycode()
{
    ::MessageBoxW(NULL,_T("析构函数"),0,IDOK);
};
void Mycode::fun()
{
    ::MessageBoxW(NULL,_T("fun函数"),0,IDOK);
};
test.cpp里定义一个全局的对象

Mycode MyTestObj;

从任务管理器的应用程序中杀死该进程,则会调用析构函数;从任务管理器的进程中直接杀死该进程,则不会调用析构函数

猜你喜欢

转载自blog.csdn.net/qq_41786318/article/details/81807320