LogiQuest
Back to Inheritance
12

What will be the output of the program?

#include <iostream>
using namespace std;
class A { public: int n = 10; };
class B : virtual public A {};
class C : virtual public A {};
class D : public B, public C {};
int main() {
    D d;
    d.n = 5;
    cout << d.B::n + d.C::n << endl;
    return 0;
}
Hard

Discussion (0)

  • No discussion yet. Ask a doubt or share a shortcut.

Log in to join the discussion.