fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. typedef void (A::*RunPtr)(int);
  7. RunPtr Run;
  8.  
  9. A()
  10. {
  11. Run = &A::RunOff;
  12. }
  13.  
  14. void SetOn(bool value)
  15. {
  16. if (value)
  17. Run = &A::RunOn;
  18. else
  19. Run = &A::RunOff;
  20. }
  21.  
  22. void RunOn(int param)
  23. {
  24. //RunOn stuff here
  25. cout << "RunOn: " << param << endl;
  26. }
  27.  
  28. void RunOff(int param)
  29. {
  30. //RunOff stuff here
  31. cout << "RunOff: " << param << endl;
  32. }
  33. };
  34.  
  35. int main() {
  36. A a;
  37. a.SetOn(true);
  38. (a.*a.Run)(1);
  39. a.SetOn(false);
  40. (a.*a.Run)(2);
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5424KB
stdin
Standard input is empty
stdout
RunOn: 1
RunOff: 2