boost::statechart "custom::reaction"

I am using boost::statechart. Instead of simple_state , using boost:: statechart::state. Now i am able to access the state_machine member variable. but when i am using custom::reaction or mpl::list it throught error. Code Snippet: struct NotReady : StateBase< NotReady, TopState > { //typedef NotReadyStateList reactions; NotReady (my_context ctx) : my_base( ctx ){ outermost_context().maxPairedDevices = 3; cout << outermost_context().maxPairedDevices << endl; } template< class MostDerived > sc::result react( const PairingBaseEvents< MostDerived > & ); public: typedef sc::custom_reaction< StartEvent > reactions; }; Error: ndefined reference to `boost::statechart::detail::safe_reaction_result NotReady::react<StartEvent>(PairingBaseEvents<StartEvent> const&)' regards Rahul Baruah

I am using boost::statechart. Instead of simple_state , using boost::statechart::state. Now i am able to access the state_machine member variable. but when i am using custom::reaction or mpl::list it throught error. Code Snippet:
struct NotReady : StateBase< NotReady, TopState > { //typedef NotReadyStateList reactions; NotReady (my_context ctx) : my_base( ctx ){ outermost_context().maxPairedDevices = 3; cout << outermost_context().maxPairedDevices << endl; }
template< class MostDerived > sc::result react( const PairingBaseEvents< MostDerived > & ); public: typedef sc::custom_reaction< StartEvent > reactions; };
Error: ndefined reference to `boost::statechart::detail::safe_reaction_result NotReady::react<StartEvent>(PairingBaseEvents<StartEvent> const&)'
Where do you define the above "react" member function template?

*.cpp file
template< class MostDerived >
sc::result NotReady::react( const PairingBaseEvents< MostDerived > &
PAEvent){
if (typeid(EntryEvent).name() == typeid(PAEvent).name())
{
outermost_context().maxPairedDevices++;
return discard_event();
}
}
i Have a mpl:list defined in another header file.
On Mon, Nov 4, 2013 at 7:00 PM, Igor R
I am using boost::statechart. Instead of simple_state , using boost::statechart::state. Now i am able to access the state_machine member variable. but when i am using custom::reaction or mpl::list it throught error. Code Snippet:
struct NotReady : StateBase< NotReady, TopState > { //typedef NotReadyStateList reactions; NotReady (my_context ctx) : my_base( ctx ){ outermost_context().maxPairedDevices = 3; cout << outermost_context().maxPairedDevices << endl; }
template< class MostDerived > sc::result react( const PairingBaseEvents< MostDerived > & ); public: typedef sc::custom_reaction< StartEvent > reactions; };
Error: ndefined reference to `boost::statechart::detail::safe_reaction_result NotReady::react<StartEvent>(PairingBaseEvents<StartEvent> const&)'
Where do you define the above "react" member function template? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Where do you define the above "react" member function template?
*.cpp file
template< class MostDerived > sc::result NotReady::react( const PairingBaseEvents< MostDerived > & PAEvent){ if (typeid(EntryEvent).name() == typeid(PAEvent).name()) { outermost_context().maxPairedDevices++; return discard_event(); } }
i Have a mpl:list defined in another header file.
If you define a function template in cpp (not in the header), you have to instantiate this definition manually for all the types that the declaration gets instantiated for. If you want to rely on automatic template instantiation, define the function in the header file.

ok..Let me give you better snippet
*SM.hpp:*
struct TopState;
struct PairingStateMachine : sc::state_machine< StateMachine, TopState >
{
unsigned int max; /**< Total number of devices
which can be paired */
};
struct NotReady;
struct TopState : sc::state< TopState, StateMachine, NotReady >
{
TopState(my_context ctx) : my_base( ctx )
{
}
~TopState() { std::cout << "Leave and desctruct TopState state!\n"; }
typedef TopstateList reactions;
template< class MostDerived >
sc::result react( const PairingBaseEvents< MostDerived > & );
};
template< class MostDerived, class Context >
struct StateBase : sc::state< MostDerived, Context>
{
typedef sc::state< MostDerived, Context> base_type;
typedef typename base_type::my_context my_context;
typedef StateBase my_base;
StateBase( my_context ctx ) : base_type( ctx )
{
std::cout << "StateBase cst" << std::endl;
}
};
struct NotReady : StateBase< NotReady, TopState >
{
typedef NotReadystateList reactions;
NotReady (my_context ctx) : my_base( ctx ){
}
template< class MostDerived >
sc::result react( const PairingBaseEvents< MostDerived > & );
};
*SM.cpp:*
template< class MostDerived >
sc::result NotReady::react( const PairingBaseEvents< MostDerived > &
PAEvent){
if (typeid(EntryEvent).name() == typeid(PAEvent).name())
{
outermost_context().maxPairedDevices++;
return discard_event();
}
}
regards
Rahul
On Tue, Nov 5, 2013 at 4:18 PM, Igor R
Where do you define the above "react" member function template?
*.cpp file
template< class MostDerived > sc::result NotReady::react( const PairingBaseEvents< MostDerived > & PAEvent){ if (typeid(EntryEvent).name() == typeid(PAEvent).name()) { outermost_context().maxPairedDevices++; return discard_event(); } }
i Have a mpl:list defined in another header file.
If you define a function template in cpp (not in the header), you have to instantiate this definition manually for all the types that the declaration gets instantiated for. If you want to rely on automatic template instantiation, define the function in the header file. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Mon, 04 Nov 2013 14:08:01 +0100, rahul baruah
I am using boost::statechart. Instead of simple_state , using boost:: statechart::state. Now i am able to access the state_machine member variable. but when i am using custom::reaction or mpl::list it throught error. Code Snippet:
struct NotReady : StateBase< NotReady, TopState > { //typedef NotReadyStateList reactions; NotReady (my_context ctx) : my_base( ctx ){ outermost_context().maxPairedDevices = 3; cout << outermost_context().maxPairedDevices << endl; }
template< class MostDerived > sc::result react( const PairingBaseEvents< MostDerived > & ); public: typedef sc::custom_reaction< StartEvent > reactions; };
Error: ndefined reference to `boost::statechart::detail::safe_reaction_result NotReady::react<StartEvent>(PairingBaseEvents<StartEvent> const&)'
As it seems your compiler cannot match your react() signature against an expected one. Without complete compiling example it is hard to predict why. Regards, Slava
participants (3)
-
Igor R
-
rahul baruah
-
Slava