根据输出,~Foo
仅针对对象c
#include <stdexcept>
#include <iostream>
struct Foo
{
const char * m_name;
Foo (const char * name) : m_name (name) {}
~ Foo ()
{
std::cerr << m_name << bool(std::current_exception ()) << std::endl;
}
};
int main ()
{
Foo a ("a");
{
Foo b ("b");
{
Foo c ("c");
}
throw 0;
}
}
输出:
c0
terminate called after throwing an instance of 'int'
为什么其他对象没有被破坏?我以为这应该发生。