특정 서명을 요구하는 Boost :: Signal에 다른 서명을 가진 함수를 연결할 수 있습니까?일반 함수/슬롯을 사용하여 boost :: 신호에 연결하는 방법은 무엇입니까?
나는 다양한 시그널을 가지고있다. 그리고 시그널의 시그니처를 신경 쓰지 않고 시그널을 관찰 할 수 있기를 원한다. 심지어 가능할까요?
예 :
float sum(float x, float y)
{
return x + y;
}
void signal_monitor(void)
{
//Do something
}
boost::signal<float (float, float)> sig;
sig.connect(&print_sum);
sig.connect(/* How to connect to signal_monitor ? */);
sig(5, 3);
그것을 할 부스트 : : 바인딩을 사용할 수 있습니까? 사용
부스트 버전 :
opt/include/boost/function/function_template.hpp: In static member function ‘static R boost::detail::function::function_obj_invoker2<FunctionObj, R, T0, T1>::invoke(boost::detail::function::function_buffer&, T0, T1) [with FunctionObj = float, R = float, T0 = float, T1 = float]’:
opt/include/boost/function/function_template.hpp:913:60: instantiated from ‘void boost::function2<R, T1, T2>::assign_to(Functor) [with Functor = float, R = float, T0 = float, T1 = float]’
opt/include/boost/function/function_template.hpp:722:7: instantiated from ‘boost::function2<R, T1, T2>::function2(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = float, R = float, T0 = float, T1 = float, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
opt/include/boost/function/function_template.hpp:1064:16: instantiated from ‘boost::function<R(T0, T1)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = float, R = float, T0 = float, T1 = float, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type = int]’
opt/include/boost/function/function_template.hpp:1105:5: instantiated from ‘typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0, T1)>&>::type boost::function<R(T0, T1)>::operator=(Functor) [with Functor = float, R = float, T0 = float, T1 = float, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, boost::function<R(T0, T1)>&>::type = boost::function<float(float, float)>&]’
opt/include/boost/signals2/detail/slot_template.hpp:156:9: instantiated from ‘void boost::signals2::slot2<R, T1, T2, SlotFunction>::init_slot_function(const F&) [with F = float, R = float, T1 = float, T2 = float, SlotFunction = boost::function<float(float, float)>]’
opt/include/boost/signals2/detail/slot_template.hpp:81:9: instantiated from ‘boost::signals2::slot2<R, T1, T2, SlotFunction>::slot2(const F&) [with F = float, R = float, T1 = float, T2 = float, SlotFunction = boost::function<float(float, float)>]’
../../../example/example.cpp:200:61: instantiated from here
opt/include/boost/function/function_template.hpp:132:42: error: ‘* f’ cannot be used as a function
opt/include/boost/function/function_template.hpp:133:9: error: control reaches end of non-void function [-Werror=return-type]
cc1plus: all warnings being treated as errors
make[1]: *** [example.o] Error 1
많은 감사들 : 나는
sig.connect((boost::phoenix::bind(&signal_monitor), 1.f)); // Return 1.f
를 사용하는 경우 1.46.1
나는 다음과 같은 오류를 얻을.
반환 유형과 값의 문제가 있습니다. –
빠른 응답 주셔서 감사합니다, 나는 컴파일 오류가 발생합니다. 만약 내가 전화를 sig.connect ((부스트 :: phoenix :: bind (& signal_monitor), 1.f)); "boost"/ function/function_template.hpp : 132 : 42 : 오류 : '* f'를 함수로 사용할 수 없습니다. " – Sak
@ user1574205 제공된 예제 (예 : 1.f를 반환하고 모든 오류는 criptic입니다. 일할 수 있으므로 더 많은 정보를 제공해야합니다. 예 : 오류 출력에 대한 링크와 사용중인 Boost 버전이 많은 도움이 될 것입니다. –