Question OOP-EXC-0065
HardWhat is the output of this code?
#include <iostream>
#include <stdexcept>
using namespace std;
#include <stdexcept>
struct G {
const char *n;
G(const char *s) : n(s) {}
~G() { cout << "~" << n << " "; }
};
void f() {
G a("a");
throw runtime_error("x");
G b("b");
}
int main() {
try {
G c("c");
f();
} catch (const exception &e) {
cout << "caught " << e.what();
}
}
- A.
caught x ~a ~c
- B.
~c ~a caught x
- C.
~a ~b ~c caught x
- D.
~a ~c caught x
Sign up free to see the answer and a step-by-step explanation.