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

发布于 2024-11-17 23:05:07 字数 504 浏览 9 评论 0原文

在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后知后觉 2024-11-24 23:05:07

您还可以从状态中执行许多其他操作<>无法从 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<>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文