fork download
  1. #include <iostream>
  2.  
  3. struct Base1 {
  4. virtual void foo() = 0;
  5. };
  6.  
  7.  
  8. struct Base2 : virtual Base1 {
  9. void foo() override {
  10. std::cout << "Base2: foo!" << std::endl;
  11. }
  12. };
  13.  
  14. struct Derived : virtual Base1, Base2 {
  15. };
  16.  
  17.  
  18. int main() {
  19. Derived d;
  20. Base1* b1 = &d;
  21. b1->foo();
  22. return 0;
  23. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Base2: foo!