It just happened to me I wondered how resources are freed in the following case.
class Base {
Resource *r;
public:
Base() { /* ... */ }
~Base() {
The base class destructor is indeed called. Sample code:
#include
#include
class Base {
public:
Base() { /* ... */ }
~Base() {
printf("Base\n");
}
};
class Derived : public Base {
public:
Derived() { /* ... */ }
~Derived() {
printf("Derived\n");
throw 1;
}
};
int main() {
try {
Derived d;
} catch(...) {
printf("CAUGHT!\n");
}
}
This prints:
Derived
Base
CAUGHT!