fork download
  1. #include <iostream>
  2.  
  3. struct Base
  4. {
  5. };
  6.  
  7. struct Fuu : public Base
  8. {
  9. void bar(){ std::cout << "Fuu::bar" << std::endl; }
  10. void bax(){ std::cout << "Fuu::bax" << std::endl; }
  11. };
  12.  
  13. struct Foo : public Base
  14. {
  15. void bar(){ std::cout << "Foo::bar" << std::endl; }
  16. void bax(){ std::cout << "Foo::bax" << std::endl; }
  17. };
  18.  
  19. typedef void (Base::*PtrToMethod)();
  20.  
  21. int main()
  22. {
  23. PtrToMethod ptr1 = (PtrToMethod) &Foo::bax;
  24. PtrToMethod ptr2 = (PtrToMethod) &Fuu::bax;
  25.  
  26.  
  27. Base *f1 = new Foo;
  28. Base *f2 = new Fuu;
  29.  
  30. (f1->*ptr1)();
  31. (f2->*ptr2)();
  32. }
  33.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
Foo::bax
Fuu::bax