Hello,
I'd like to share some functionality between states belonging to
different (but similar) FSMs. I try to do this by taking out some part
of a state to a base class template:
template
struct ActiveBase : state
{
// this's probably not quite standard, but it should be fine with msvc
ActiveBase(my_context ctx) : my_base(ctx)
{}
void f(const Event1 &)
{}
};
struct Active;
struct FSM : asynchronous_state_machine
{
//...
};
struct Active : ActiveBase
{
Active(my_context ctx) : ActiveBase(ctx)
{}
typedef mpl::list
<
sc::in_state_reaction
reactions;
};
However, this doesn't compile:
1>..\boost/statechart/state_machine.hpp(493) : error C2440: 'return' :
cannot convert from 'FSM' to 'ActiveBase &'
1> with
1> [
1> Derived=Active,
1> Outer=FSM,
1> Inner=boost::mpl::list<Disconnected>
1> ]
1> ../boost/statechart/simple_state.hpp(684) : see reference to
function template instantiation 'Context
&boost::statechart::state_machine::context<OtherContext>(void)'
being compiled
1> with
1> [
1> Context=ActiveBase,
1> MostDerived=FSM,
1> InitialState=Active,
1> Allocator=std::allocator<void>,
1> ExceptionTranslator=boost::statechart::null_exception_translator,
1> OtherContext=ActiveBase
1> ]
etc........
Of course, the above snippet is not the real code, and maybe I miss
the problem in some other place, but I just would like to know if the
above approach legitimate and *should* compile.
Thanks.