fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. typedef int(*FuncType[8])(int);
  5. bool a=false, b=false, c=false;
  6.  
  7. int A(int Current) {
  8. cout << "-----> FuncA" << endl;
  9. return 2;
  10. }
  11.  
  12. int B(int Current) {
  13. cout << "-----> FuncB" << endl;
  14. c = true; // тут типа управляем выходом из бесконечного цикла
  15. return 2;
  16. }
  17.  
  18. int C(int Current) {
  19. cout << "-----> FuncC" << endl;
  20. return 6;
  21. }
  22.  
  23. int D(int Current) {
  24. cout << "-----> FuncD" << endl;
  25. return 1;
  26. }
  27.  
  28. int E(int Current) {
  29. cout << "-----> FuncE" << endl;
  30. return -1;
  31. }
  32.  
  33. int JmpA(int Current) {
  34. cout << "JmpA" << endl;
  35. return (a) ? 0 : 6;
  36. }
  37.  
  38. int JmpB(int Current) {
  39. cout << "JmpB" << endl;
  40. return (b) ? 1 : 7;
  41. }
  42.  
  43. int JmpC(int Current) {
  44. cout << "JmpC" << endl;
  45. return (c) ? 4 : 3;
  46. }
  47.  
  48. int main() {
  49. int StepNo = 5;
  50. FuncType Func = {A, B, C, D, E, JmpA, JmpB, JmpC};
  51. while((StepNo = (*Func[StepNo])(StepNo)) >= 0);
  52. return 0;
  53. }
Success #stdin #stdout 0s 3144KB
stdin
Standard input is empty
stdout
JmpA
JmpB
JmpC
-----> FuncD
-----> FuncB
-----> FuncC
JmpB
JmpC
-----> FuncE