#include class fsmOne { private: int _state; public: fsmOne() : _state(0) {} ~fsmOne() {} void loop() { std::cout << "S1." << _state << std::endl; switch (_state) { case 0: _state = 1; break; case 1: _state = 5; break; case 5: break; } return; } void reset() { _state = 0; } bool end() const { return( _state == 5 ); } }; class fsmTwo { private: fsmOne one; int _state; public: fsmTwo() : _state(0) {} ~fsmTwo() {} void loop() { std::cout << "S2." << _state << std::endl; switch (_state) { case 0: _state = 1; one.reset(); break; case 1: one.loop(); if (one.end()) { _state = 5; } break; case 5: break; } return; } void reset() { _state = 0; } bool end() const { return( _state == 5 ); } }; int main(int argc, char const *argv[]) { fsmTwo two; do { two.loop(); } while (!two.end()); return 0; }