There are several ways you can implement a finite state machine using C++. The easiest and fastest way probably is to use the enumerator type and the switch-case statement. However, in this tutorial, we are not going to do that. Instead, we will use a slightly sophisticated, more robust, generic class-based approach to reuse across multiple projects.
At the same time, we also want to extend the functionality by using functors in the same framework. But first, let’s recap on what is a Finite State Machine.
Finite State Machine (or FSM in short) is a computational pattern that defines and models state behaviour. At any given time, a Finite State Machine can exist in only one state out of a set of a possible number of states. This state can change to another in response to some inputs (sometimes called events).
The process of switching from one state to another is called a transition.
Read the tutorial on https://faramira.com/reusable-finite-state-machine-using-cpp/