【发布时间】:2013-03-05 04:25:16
【问题描述】:
函数 f() 和 g() 结束时会发生什么?
#include<iostream>
using namespace std;
class A
{
~A(){}
}
void f()
{
cout << "terminate" << endl;
}
void g()
{
cout << "unexpected" << endl;
}
int main()
{
set_terminate(f);
set_unexpected(g);
throw 5;
cout << "end" << endl;
return 0;
}
为什么叫abort()函数? 什么时候被称为破坏者?我找不到逻辑:(((((((()
【问题讨论】:
-
当它所属的类的实例超出范围时,将调用析构函数。在你的情况下,那永远不会,因为你没有 A 的实例。