在 Boost.Statechart 中,state 和 simple_state 有什么区别?

In Boost.Statechart, what's the difference between state and simple_state?

本文关键字:state 什么 区别 simple Boost Statechart      更新时间:2023-10-16

在使用Boost实现状态机时。在Statechart中,我遇到了一个问题,这个问题是由于试图从simple_state的构造函数访问它的外部上下文而引起的。simple_state.hpp中的一条评论告诉我:

    // This assert fails when an attempt is made to access an outer 
    // context from a constructor of a state that is *not* a subtype of
    // state<>. To correct this, derive from state<> instead of
    // simple_state<>.

除了能够从构造函数访问外部上下文之外,使用state<>而不是simple_state<>作为我的状态的基类还有什么区别或含义?

从一个状态可以做许多其他事情<>无法从simple_state<>执行的派生构造函数派生构造函数。文档中有一个状态类的列表。我发现发布活动是从状态<>中获得的巨大好处。

我已经有一段时间没有使用它了,但我不记得有任何含义,除了你必须为从state派生的每个类实现转发构造函数(在文档中说明),如state<>从simple_state<>派生。