fork(1) download
  1. #include <iostream>
  2.  
  3. class B
  4. {
  5. protected:
  6. int x;
  7.  
  8. protected:
  9.  
  10. B(int x) : x{x}{std::cout << x << std::endl;}
  11. };
  12.  
  13. class B1 : virtual public B
  14. {
  15. protected:
  16.  
  17. B1() : B(0){}
  18. };
  19.  
  20. class B2 : virtual public B
  21. {
  22. protected:
  23.  
  24. B2() : B(10){}
  25. };
  26.  
  27. class D : public B1, public B2
  28. {
  29. public:
  30.  
  31. D() : B{99}, B1{}, B2{} {}
  32. void print() {std::cout << "Final: " << x << std::endl;}
  33. };
  34.  
  35. int main() {
  36. D d;
  37. d.print();
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘D::D()’:
prog.cpp:17:5: error: ‘B1::B1()’ is protected
     B1() : B(0){}
     ^
prog.cpp:31:27: error: within this context
     D() : B{99}, B1{}, B2{} {}
                           ^
prog.cpp:24:5: error: ‘B2::B2()’ is protected
     B2() : B(10){}
     ^
prog.cpp:31:27: error: within this context
     D() : B{99}, B1{}, B2{} {}
                           ^
stdout
Standard output is empty