fork download
  1. #include<iostream>
  2. using namespace std;
  3. class a
  4. {
  5. public:
  6. void add(int x)
  7. {
  8. cout<<x+x<<endl;
  9. }
  10. void mult(int x)
  11. {
  12. cout<<x*x<<endl;
  13. }
  14. typedef void (a::*fptr)(int);
  15. fptr retFuncP(char ch)
  16. {
  17. if(ch=='+')
  18. {
  19. return &a::add;
  20. }
  21. else
  22. {
  23. return &a::mult;
  24. }
  25. }
  26. };
  27. int main()
  28. {
  29. a objA;
  30. void (a::*fptr)(int) = objA.retFuncP('+');
  31. (objA.*fptr)(3);
  32. cin.ignore();
  33. }
Success #stdin #stdout 0s 3300KB
stdin
Standard input is empty
stdout
6