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