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

using namespace std;

class A {
  int j;
public:
  A(int i) : j(i) { }

  void print()
  {
    cout << sizeof(j) << endl;
  }
};

class B : virtual public A {
public:
  B(int i) : A(i) { }
};

class C : public B {
public:
  C(int i) : B(i) { }
};

int main(int argn, char * argv[])
{
  C c(1);
  c.print();
  return 0;
}
Explanation
Virtual class A does not have a default constructor. Since for virtual classes, the constructor is called (explicitly or implicitly) from the lower class in the hierarchy (in this case, implicitly from C), the code will not compile.

Слідкуй за CodeGalaxy

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

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