fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Foo {
  6. public:
  7. void func(int param) { cout << param << endl; }
  8. void (Foo::*getPointer())(int) { return &Foo::func; }
  9. };
  10.  
  11. class Bar {
  12. Foo foo;
  13. public:
  14. Bar(Foo param) : foo(param) {}
  15. void print(int param) {
  16. void (Foo::*func)(int) = foo.getPointer();
  17.  
  18. (foo.func)(param);
  19. }
  20. };
  21.  
  22. int main() {
  23. Foo foo;
  24. Bar bar(foo);
  25.  
  26. bar.print(13);
  27. return 0;
  28. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
13