Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- void Action_1();
- void Action_2();
- void Action_3();
- std::function<void()> action;
- // this function in your case is not handled by you
- void setNextAction(std::function<void()> nextAction) {
- action = nextAction;
- }
- // your code
- void Action_1() {
- std::cout << "Action 1\n"; // do some action
- setNextAction(Action_2); // set next action
- }
- void Action_2() {
- std::cout << "Action 2\n"; // do some action
- setNextAction(Action_3); // set next action
- }
- void Action_3() {
- std::cout << "Action 3\n"; // do some action
- setNextAction(Action_1); // set next action
- }
- int main() {
- action = Action_1; // set initial action
- // call action 10 times (aka click button 10 times)
- for (int i = 0; i < 10; ++i) {
- action();
- }
- std::cin.get();
- }
- /*
- output:
- Action 1
- Action 2
- Action 3
- Action 1
- Action 2
- Action 3
- Action 1
- Action 2
- Action 3
- Action 1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement