fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. struct B {
  6. void f(int && a){
  7. cout << "B::f(int&&) "; }
  8. virtual int f() const {
  9. cout << "B::f() "; return 0;}
  10. };
  11. struct D : B {
  12. virtual void f(int a){
  13. cout << "D::f(int) "; }
  14. virtual int f()const {
  15. cout << "D::f() "; return 0;}
  16. };
  17. struct C : D {
  18. void f(int a) {
  19. cout << "C::f(int) "; }
  20. int f() const {
  21. cout << "C::f() "; return 0;
  22. }
  23. };
  24.  
  25. int main() {
  26. C c;
  27. D d;
  28. B * p = &d;
  29. D * q = &c;
  30. q -> f(1);
  31. q -> f();
  32. p -> f(2);
  33. p -> f();
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
C::f(int)  C::f() B::f(int&&)  D::f()