在Boost.Statechart中,state和simple_state有什么区别?
在使用 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<>
作为我的状态的基类?
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<>.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以从状态中执行许多其他操作<>无法从 simple_state<> 执行的派生构造函数派生构造函数。文档中有一个状态类的列表。我发现发布事件是从状态派生的一大好处。
自从我使用它以来已经有一段时间了,但我不记得有任何影响,除了您必须为从状态派生的每个类(文档中所述)实现转发构造函数,如 state<> 。源自 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<>.
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<>.