Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I hide the inner workings of a state machine from its clients?

0
Posted

How can I hide the inner workings of a state machine from its clients?

0

To see why and how this is possible it is important to recall the following facts: • Member functions of a C++ class template are instantiated at the point where they’re actually called. If the function is never called, it will not be instantiated and not a single assembly instruction will ever be generated • The InitialState template parameter of sc::state_machine can be an incomplete type (i.e. forward declared) The class template member function state_machine<>::initiate() creates an object of the initial state. So, the definition of this state must be known before the compiler reaches the point where initiate() is called. To be able to hide the initial state of a state machine in a .cpp file we must therefore no longer let clients call initiate(). Instead, we do so in the .cpp file, at a point where the full definition of the initial state is known. Example: StopWatch.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123