#include struct fsmOne { int state = 0; bool operator()() { std::cout << "S1." << state << std::endl; switch (state) { case 0: state = 1; break; case 1: state = 5; break; case 5: return( true ); } return( false ); } }; struct fsmTwo { int state = 0; fsmOne one; bool operator()() { std::cout << "S2." << state << std::endl; switch (state) { case 0: state = 1; one.state = 0; break; case 1: if (one()) { state = 5; } break; case 5: return( true ); } return( false ); } }; int main(int argc, char const *argv[]) { fsmTwo two; while (!two()) {} return 0; }