In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to implement C++ finite state machine". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn how to implement the C++ finite state machine.
Catalogue
Four elements of finite state machine
Pointer implementation of C++ function
Four elements of finite state machine
Present state: current state
Secondary state: the next state to be transferred when the condition is met.
Action: an action performed when an event is satisfied; after the action is completed, it can be transferred to another state or maintained.
Condition: a condition required to transfer a state, which triggers an action or makes a state transition when the condition is met.
Pointer implementation of C++ function
Case study: students' daily life.
Students' daily life includes the following states: get up, go to school, have lunch, do homework, and go to bed.
The transition between each state requires the execution of the corresponding event.
I am divided into the following steps to achieve:
(1) draw the state transition diagram
(2) create a state transition FSMItem class
Enumeration: all state State, all event Event
Member variables: current _ curState, event _ event, secondary _ nextState
Member functions: action function
(3) create the finite state machine FSM class
Member variables: state transition table vector _ fsmTable
Member functions: initialize state transition table, state transition, and perform corresponding actions according to events
(4) Test FSM
(1) draw the state transition diagram
(2) FSMItem class
/ / FSM status item class FSMItem {friend class FSM;private: / / Action function static void getUp () {cout
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.