← Quiz: Multiple Inheritance and the Diamond Problem: all 10 questions
Quiz: Multiple Inheritance and the Diamond Problem · Question 7 of 10
What does this print? (code)
What does this print?
#include <iostream>
using namespace std;
struct D { D() { cout << "D"; } };
struct P : virtual D { P() { cout << "P"; } };
struct S : virtual D { S() { cout << "S"; } };
struct X : P, S { X() { cout << "X"; } };
int main() {
X x;
return 0;
}
- A.DPDSX
- B.DPSX
- C.PSDX
- D.PSX
Answer & explanation
Correct answer: DPSX
D is a virtual base, so it is built once, first; then P, S and finally X.
Can you get the rest right without peeking?
Take the timed Quiz: Multiple Inheritance and the Diamond Problem quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →