Listing 2: Base state machine classes.

#ifdef DERIVE_STATE_MACHINE 

#define THIS            (*this)

template <class T, class EV, class CMP = std::less<EV> >
class StateMachine : private T
{
public: 
    explicit StateMachine( State<T,EV,CMP>* const stStart ) : 
        T(), m_stStart(stStart), m_stCurrent(stStart), m_stThis(eStopped) {}
// Aggregated Version of State Machine
#else
#define THIS            (*m_T)
template <class T, class EV, class CMP = std::less<EV> >
class StateMachine
{
private:
    T* m_T;
public: 
    explicit StateMachine( T* _T, State<T,EV,CMP>* const stStart ) : 
      m_T(_T), m_stStart(stStart), m_stCurrent(stStart), m_stThis(eStopped) {}
    ~StateMachine() { delete m_T; }

#endif      // DERIVE_STATE_MACHINE
    ... // other API functions not shown
private: 
    State<T,EV,CMP>* const m_stStart;
    State<T,EV,CMP>* m_stCurrent;
};