fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo
  5. {
  6. int x;
  7. public:
  8. Foo(int n) : x(n) { }
  9. int foo(int y) { return x + y; }
  10. int bar(int y) { return x * y; }
  11. };
  12.  
  13. int main() {
  14. int (Foo::* mp)(int) = &Foo::foo; // wskaźnik na metodę klasy
  15. Foo a(5), b(17);
  16. cout << (a.*mp)(3) << endl;
  17. cout << (b.*mp)(3) << endl;
  18. mp = &Foo::bar;
  19. cout << (a.*mp)(3) << endl;
  20. cout << (b.*mp)(3) << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3096KB
stdin
Standard input is empty
stdout
8
20
15
51