使用Boost状态图,如何无条件转换到某个状态?
我有一个状态 A
,一旦 A
的构造函数完成,我希望无条件转换到其下一个状态 B
。这可能吗?
我尝试从构造函数发布一个事件,尽管它可以编译,但它不起作用。谢谢。
编辑:这是我到目前为止所尝试的:
struct A : sc::simple_state< A, Active >
{
public:
typedef sc::custom_reaction< EventDoneA > reactions;
A()
{
std::cout << "Inside of A()" << std::endl;
post_event( EventDoneA() );
}
sc::result react( const EventDoneA & )
{
return transit< B >();
}
};
这会产生以下运行时断言失败:
Assertion failed: get_pointer( pContext_ ) != 0, file /includ
e/boost/statechart/simple_state.hpp, line 459
I have a state A
that I would like to transition to its next state B
unconditionally, once the constructor of A
has completed. Is this possible?
I tried posting an event from the constructor, which does not work, even though it compiles. Thanks.
Edit: Here is what I've tried so far:
struct A : sc::simple_state< A, Active >
{
public:
typedef sc::custom_reaction< EventDoneA > reactions;
A()
{
std::cout << "Inside of A()" << std::endl;
post_event( EventDoneA() );
}
sc::result react( const EventDoneA & )
{
return transit< B >();
}
};
This yields the following runtime assertion failure:
Assertion failed: get_pointer( pContext_ ) != 0, file /includ
e/boost/statechart/simple_state.hpp, line 459
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经用我的解决方案更新了我的OP,在这里我可以关闭问题。
问题是您无法从
simple_state
继承来实现所需的转换,您必须从state
继承,然后需要您相应地修改构造函数。I've updated my OP with my solution, here it is so I can close the question.
The problem is that you cannot inherit from
simple_state
to achieve the desired transition, you must inherit fromstate
, which then requires that you modify the constructor accordingly.