fork download
  1. #include <iostream>
  2.  
  3. struct Foo
  4. {
  5.  
  6. };
  7.  
  8. struct Bar : public Foo
  9. {
  10. int F0()
  11. {
  12. return 0;
  13. }
  14. };
  15.  
  16. struct Baz : public Foo
  17. {
  18. int F1()
  19. {
  20. return 1;
  21. }
  22. };
  23.  
  24. int main(int argc, char **argv)
  25. {
  26. int (Bar::*pF0)() = &Bar::F0;
  27. int (Baz::*pF1)() = &Baz::F1;
  28. int (Foo::*pointer1)() = static_cast<int (Foo::*)()>(pF0);
  29. int (Foo::*pointer2)() = static_cast<int (Foo::*)()>(pF1);
  30.  
  31. Bar r;
  32. Baz z;
  33.  
  34. std::cout << (r.*pointer1)() << '\n';
  35. std::cout << (z.*pointer2)() << '\n';
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
0
1