fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Base {
  5. virtual void foo() {
  6. cout << "Base::foo()" << endl;
  7. }
  8.  
  9. virtual void bar() {
  10. cout << "Base::bar()" << endl;
  11. }
  12. };
  13.  
  14. struct Derived1 : public Base {
  15. void bar() override {
  16. Base::bar();
  17. }
  18. };
  19.  
  20. struct Derived2 : public Base {
  21. void bar() override {
  22. Base::bar();
  23. }
  24. };
  25.  
  26. struct Derived : public Derived1,Derived2 {
  27. void bar() override {
  28. cout << "Derived::bar()" << endl;
  29. Derived1::bar();
  30. Derived2::bar();
  31. }
  32. };
  33.  
  34. int main() {
  35. Derived d;
  36. d.bar();
  37. return 0;
  38. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Derived::bar()
Base::bar()
Base::bar()