Boost logo

Boost Users :

From: Jiang Miao (jiangfriend_at_[hidden])
Date: 2007-07-24 04:04:59


I wrote a simple code.
source file:
#include <boost/statechart/event.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/custom_reaction.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/mpl/list.hpp>
#include <iostream>
#include <string>
using namespace std;
namespace sc=boost::statechart;
namespace mpl=boost::mpl;

struct EvtEat:sc::event<EvtEat>{};
struct EvtStop:sc::event<EvtStop>{};

struct Eating;
struct Idle;

class Human:public sc::state_machine< Human, Idle >
    {
    public:
        void show(void)
            {
            cout<<__FUNCTION__<<endl;
            }
    };

struct Idle:sc::state< Idle, Human >
    {
    Idle(my_context ctx):my_base(ctx)
        {
        context<Human>().show(); //ok
        };
    ~Idle(void)
        {
        context<Human>().show(); //assert failed
        };
    };

struct Eating:sc::state< Eating, Human >
    {
    Eating(my_context ctx):my_base(ctx)
        {
        };
    ~Eating(void)
        {
        context<Human>();
        }
    };

int main(int argc, char* argv[])
    {
    Human human;
    human.initiate();
    return 0;
    }

/*
In debug mode.It output

Human::show
Assertion failed: dynamic_cast<Target>(x) == x, file
p:\programme\libs\boost\include\boost-1_35\boost\cast.hpp, line 97
*/

Why does it assert failed and how to modify the source?

Thank you.



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