[signals] signals::slot_type not working?
Hi, below is my code: template< InputSubscription t_sub > static void subscribe( SignalBank const& bank, typename GetSignal<t_sub>::signal::slot_type& slot ) { using boost::fusion::at_c; at_c<t_sub>( bank.signals ).connect( slot ); } void mouseCB( int, int ) { } void footest() { SignalBank bank; //boost::fusion::at_c<1>( bank.signals )( 3, 4 ); subscribe<INPUTSUB_MOUSE_MOTION>( bank, &mouseCB ); }; Notice that I have a wrapper function, 'subscribe', which uses the slot_type member of the signals class to pass the slot to the connect() function. However, visual studio 9 reports the following error: *error C2664: 'bob::input::subscribe' : cannot convert parameter 2 from 'void (__cdecl *)(int,int)' to 'boost::slot<SlotFunction> &' with [ SlotFunction=boost::function<void (int,int)> ] *Any solutions to fix the problem?* *
Robert Dailey wrote:
template< InputSubscription t_sub > static void subscribe( SignalBank const& bank, typename GetSignal<t_sub>::signal::slot_type& slot ) { using boost::fusion::at_c; at_c<t_sub>( bank.signals ).connect( slot ); }
void footest() { subscribe<INPUTSUB_MOUSE_MOTION>( bank, &mouseCB ); };
Notice that I have a wrapper function, 'subscribe', which uses the slot_type member of the signals class to pass the slot to the connect() function.
Try making that 'const ...::slot_type&' instead?
On Feb 6, 2008 1:56 PM, Nat Goodspeed <nat@lindenlab.com> wrote:
Try making that 'const ...::slot_type&' instead?
I tried that too, but the error gets even more crazy: *1>c:\it\personal\rocket_test\source\inputtest.cpp(48) : error C2663: 'boost::signal2<R,T1,T2,Combiner,Group,GroupCompare,SlotFunction>::connect' : 2 overloads have no legal conversion for 'this' pointer 1> with 1> [ 1> R=void, 1> T1=int, 1> T2=int, 1> Combiner=boost::last_value<void>, 1> Group=int, 1> GroupCompare=std::less<int>, 1> SlotFunction=boost::function<void (int,int)> 1> ] 1> c:\it\personal\rocket_test\source\inputtest.cpp(61) : see reference to function template instantiation 'void bob::input::subscribe<INPUTSUB_MOUSE_MOTION>(const bob::input::SignalBank &,const boost::slot<SlotFunction> &)' being compiled 1> with 1> [ 1> SlotFunction=boost::function<void (int,int)> 1> ]*
Hmm, I think I found the issue. My signal object is const for some reason. I'm doing a lot of tricks to map enums to signal objects, I'll post all the code at the bottom of this message. My fusion::vector either must be containing the signal objects as const, or fusion::at_c must be returning const. I'm not really sure. namespace detail { template< InputSubscription t_sub > struct sub { const static InputSubscription value = t_sub; }; using boost::mpl::map; using boost::mpl::pair; typedef map< pair< sub<INPUTSUB_KEYBOARD>, boost::signal<void (unsigned int, bool)> >, pair< sub<INPUTSUB_MOUSE_MOTION>, boost::signal<void (int, int)> >, pair< sub<INPUTSUB_MOUSE_BUTTON>, boost::signal<void (int, int, unsigned int, bool)> >, pair< sub<INPUTSUB_MOUSE_WHEEL>, boost::signal<void (int)> > > SubMap; } /// Obtains a boost::signal from a matching InputSubscription identifier. template< InputSubscription t_sub > struct GetSignal { typedef typename boost::mpl::at<detail::SubMap, detail::sub<t_sub>
::type signal; };
struct SignalBank { boost::fusion::vector< GetSignal<INPUTSUB_KEYBOARD>::signal, GetSignal<INPUTSUB_MOUSE_MOTION>::signal, GetSignal<INPUTSUB_MOUSE_BUTTON>::signal, GetSignal<INPUTSUB_MOUSE_WHEEL>::signal > signals; }; template< InputSubscription t_sub > static void subscribe( SignalBank const& bank, typename GetSignal<t_sub>::signal::slot_type const& slot ) { using boost::fusion::at_c; const_cast<GetSignal<t_sub>::signal>( at_c<t_sub>( bank.signals ) ).connect( slot ); } void mouseCB( int, int ) { } void footest() { SignalBank bank; //boost::fusion::at_c<1>( bank.signals )( 3, 4 ); subscribe<INPUTSUB_MOUSE_MOTION>( bank, &mouseCB ); };
Oh god, how embarrassing. My 'subscribe()' function was passing in the SignalBank object as a const reference! Doh! Problem solved.
participants (2)
-
Nat Goodspeed
-
Robert Dailey