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

时间:2011-06-30 03:05:43

标签: c++ state-machine boost-statechart

在使用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<>作为我的状态的基类有什么不同或含义?

1 个答案:

答案 0 :(得分:3)

您可以通过州&lt;&gt;进行其他一些操作。派生的构造函数,你不能从simple_state&lt;&gt;派生的构造函数。州级文档中有一个列表。我发现发布事件是从州&lt;&gt;得到的最大好处。

自从我使用它已经有一段时间了,但我不记得有任何影响,除了你必须为从状态派生的每个类(在docs中说明)实现转发构造函数,作为state&lt;&gt;源自simple_state&lt;&gt;。

相关问题