fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base1
  5. {
  6. public:
  7. void print(const char *str){ cout << "base1 " << str << endl; }
  8. };
  9.  
  10. class Base2
  11. {
  12. public:
  13. void print(const char *str){ cout << "base2 " << str << endl; }
  14. };
  15.  
  16. class Derived : public Base1, public Base2
  17. {
  18. public:
  19. void print(const char *str);
  20. };
  21.  
  22. void Derived::print(const char *str)
  23. {
  24. cout << "Derived " << str << endl;
  25. Base1::print(str);
  26. Base2::print(str);
  27. }
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31. Derived d;
  32. d.print("hello");
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Derived hello
base1 hello
base2 hello