fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct B {
  6. int f() { cout << "B::F\n"; }
  7. };
  8.  
  9. struct A { int x; A() : x(42) {} };
  10.  
  11. struct D : A, B {
  12. int g() { cout << "D::G" << x << "\n"; }
  13. };
  14.  
  15. int main()
  16. {
  17. D d;
  18. B b;
  19. B* pb = &b;
  20. int (B::*pf)() = &B::f;
  21. (pb->*pf)();
  22.  
  23. pb = &d;
  24. pf = (int(B::*)())&D::g;
  25. (pb->*pf)();
  26. return 0;
  27.  
  28. }
  29.  
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
B::F
D::G42