fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. int a;
  5. };
  6.  
  7. struct B : virtual public A {
  8. };
  9.  
  10. struct C : virtual public A {
  11. };
  12.  
  13. struct D : virtual public B, virtual public C {
  14. void d1() { a = 1; }
  15. void d2() { a = 2; }
  16. };
  17.  
  18. int main() {
  19. D d;
  20. d.d1();
  21. d.d2();
  22. std::cout << d.a << std::endl;
  23. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
2