Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. void Action_1();
  5. void Action_2();
  6. void Action_3();
  7.  
  8. std::function<void()> action;
  9.  
  10. // this function in your case is not handled by you
  11. void setNextAction(std::function<void()> nextAction) {
  12.     action = nextAction;
  13. }
  14.  
  15. // your code
  16. void Action_1() {
  17.     std::cout << "Action 1\n"; // do some action
  18.     setNextAction(Action_2);   // set next action
  19. }
  20. void Action_2() {
  21.     std::cout << "Action 2\n"; // do some action
  22.     setNextAction(Action_3);   // set next action
  23. }
  24. void Action_3() {
  25.     std::cout << "Action 3\n"; // do some action
  26.     setNextAction(Action_1);   // set next action
  27. }
  28.  
  29. int main() {
  30.     action = Action_1; // set initial action
  31.  
  32.      // call action 10 times (aka click button 10 times)
  33.     for (int i = 0; i < 10; ++i) {
  34.         action();
  35.     }
  36.  
  37.     std::cin.get();
  38. }
  39.  
  40. /*
  41.     output:
  42.  
  43.     Action 1
  44.     Action 2
  45.     Action 3
  46.     Action 1
  47.     Action 2
  48.     Action 3
  49.     Action 1
  50.     Action 2
  51.     Action 3
  52.     Action 1
  53. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement