What will be printed out as a result of the following code execution?
#include <iostream>
using namespace std;

class A {
public:
    virtual void foo(){ cout<<"A"; }
};

class B: public virtual A {
public:
    virtual void foo(){ cout<<"B"; }
};

class C: public virtual A {};
class D: public B, public C {};

int main(void) {
    D d;
    C &c = d;
    c.foo();
    return 0;
}
Explanation
"B" is printed out, as classes B and C have virtual inheritance and therefore, class D will have only one instance of class A and, correspondignly, one pointer to the virtual function table, where B::foo() is specified.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести