fork download
  1. #include <iostream>
  2.  
  3. struct Base
  4. {
  5. virtual void f(int x)
  6. {
  7. std::cout << "Base::f(int) called with " << x << std::endl;
  8. }
  9. virtual void f(double x)
  10. {
  11. std::cout << "Base::f(double) called with " << x << std::endl;
  12. }
  13. };
  14.  
  15. struct Derived
  16. : Base
  17. {
  18. void f(int x)
  19. {
  20. std::cout << "Derived::f(int) called with " << x << std::endl;
  21. }
  22. };
  23.  
  24. int main()
  25. {
  26. Derived d;
  27. Base &b = d;
  28. b.f(7);
  29. b.f(3.14);
  30. }
  31.  
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
Derived::f(int) called with 7
Base::f(double) called with 3.14