Boost logo

Boost Users :

Subject: Re: [Boost-users] [statechart] StopWatch aborts on context<StopWatch>()
From: Andreas Huber (ahd6974-spamboostorgtrap_at_[hidden])
Date: 2009-03-05 14:40:43


Hi

[snip]
> just to give an example:
> if i add the following line in the
> boost/libs/statechart/examples/StopWatch/StopWatch.cpp file
> Running() : startTime_( std::time( 0 ) ) {
> context<StopWatch>(); // <<< added
> }
>
> it compiles and abort's if i try to start the stopwatch

Yep, that's expected. I quote the comment immediately above the assert:

// 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<>.

> i dont understand why? the state_machine is initialized and even the docs
> say in its comments that i can use it to get the statemachine
> http://www.boost.org/doc/libs/1_38_0/libs/statechart/doc/tutorial.html#StateLocalStorage
>
> but im sure i just miss something

Please read:
<http://www.boost.org/doc/libs/1_38_0/libs/statechart/doc/tutorial.html#PostingEvents>

This is about posting events from state constructors but applies to
context<> too. Also, please see the preconditions for context documented
after "Requires:":

<http://www.boost.org/doc/libs/1_38_0/libs/statechart/doc/reference.html#context>

HTH,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net