在Boost.Statechart中,state和simple_state有什么区别? [英] In Boost.Statechart, what's the difference between state and simple_state?
问题描述
在使用Boost.Statechart实现状态机时,我遇到了一个问题,它试图从它的构造函数访问 simple_state
的外部上下文。 simple_state.hpp
中的注释告诉我:
In implementing a state machine using Boost.Statechart, I came across a problem arising from attempting to access the outer context of a simple_state
from its constructor. A comment in simple_state.hpp
tells me:
// 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<>
作为我的状态的基类?
Apart from apparently being able to access the outer context from its constructor, what differences or implications are there in using state<>
instead of simple_state<>
as the base class for my states?
推荐答案
有一些其他的事情,你可以从状态<>派生构造函数做,你不能从一个simple_state派生构造函数。在状态类的文档中有一个列表。我发现发布事件是从状态<>导出的大的好处。
There are a number of other things that you can do from a state<> derived constructor that you cannot do from a simple_state<> derived constructor. There are a list in the documentation for the state class. I found posting events to be the big benefit of deriving from state<>.
这是一段时间,因为我使用它,但我不记得有任何暗示,除了你必须为从状态派生的每个类(在docs中说明)实现转发构造函数,因为状态<>是从simple_state<>派生的。
It's been a while since I used it, but I don't remember there being any implications, other than you having to implement the forwarding constructor for each class derived from state (stated in docs), as state<> is derived from simple_state<>.
这篇关于在Boost.Statechart中,state和simple_state有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!