ProgrammingVery hardProduct-company placement · C++

What is printed?

What is printed?
struct E { };
struct F : private E { };
int main() {
    try { throw F(); }
    catch (E&) { cout << "E"; }
    catch (...) { cout << "?"; }
}
  1. A. E
  2. B. Compile-time error: E is an inaccessible base
  3. C. Nothing; std::terminate is called
  4. D. ?

Correct answer: D. ?

A handler for a base class matches only if that base is an unambiguous PUBLIC base of the thrown type. E is a private base of F, so the exception falls through to catch (...).

More OOP with C++ and Java questions

Exams that ask this topic