#include #include #include using namespace std; struct noisy { noisy () { cout << "noisy::noisy @ " << this << "\n"; } ~noisy () { cout << "noisy::~noisy @ " << this << "\n"; } }; struct thrower { thrower (int i) { throw i; } }; struct example { auto_ptr m_noisy; thrower m_thrower; example () : m_noisy (new noisy ()), m_thrower (42) { // oops - we won't make it here } }; int main (int argc, char* argv[]) { try { example ex; } catch (int& i) { // Catch the exception thrown by the "thrower" class. We // should see that the "noisy" object was destroyed *before* // we get here courtesy of the auto_ptr cout << i << "\n"; } }