Boost logo

Boost Users :

Subject: [Boost-users] [Signals2] How to connect member functions with more than one argument?
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2010-01-07 03:26:45


Dear all,

I am new to Boost.Signals2, so sorry for the possibly trivial question.
My problem is that I am not able to connect a member function with
more than one argument to a signal.
My test code is the following:

--- [code] ---
#include <boost/bind.hpp>
#include <boost/signals2.hpp>
#include <iostream>

template <typename IntT=int, typename RealT=double>
struct event_consumer
{
    typedef IntT int_type;
    typedef RealT real_type;
    typedef boost::signals2::signal<void (int_type,real_type)> signal_type;
    typedef event_consumer<int_type,real_type> self_type;

    void consume()
    {
        sig.connect(boost::bind(&self_type::process, this, _1));

        sig(2,0.5);
    }

    void process(int_type x, real_type y)
    {
        std::cout << "X: " << x << " -- Y: " << y << std::endl;
    }

    signal_type sig;
};

int main()
{
    event_consumer<> consumer;

    consumer.consume();
}
--- [/code] ---

When I compile it (with g++ 4.4.2 and flags --ansi --Wall) I get this error:

--- [error] ---
$ g++ -Wall -ansi -o test_signal test_signal.cpp
In file included from .../boost/bind.hpp:22,
                 from test_signal.cpp:1:
.../boost/bind/bind.hpp: In instantiation of
‘boost::_bi::result_traits<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double)>’:
...//boost/bind/bind_template.hpp:15: instantiated from
‘boost::_bi::bind_t<boost::_bi::unspecified, void (event_consumer<int,
double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >’
test_signal.cpp:15: instantiated from ‘void event_consumer<IntT,
RealT>::consume() [with IntT = int, RealT = double]’
test_signal.cpp:32: instantiated from here
.../boost/bind/bind.hpp:69: error: ‘void (event_consumer<int,
double>::*)(int, double)’ is not a class, struct, or union type
In file included from ...//function/detail/maybe_include.hpp:23,
                 from .../boost/function/detail/function_iterate.hpp:14,
                 from
.../boost/preprocessor/iteration/detail/iter/forward1.hpp:57,
                 from .../boost/function.hpp:64,
                 from .../boost/signals2/signal.hpp:18,
                 from .../boost/signals2.hpp:16,
                 from test_signal.cpp:2:
.../boost/function/function_template.hpp: In static member function
‘static void boost::detail::function::void_function_obj_invoker2<FunctionObj,
R, T0, T1>::invoke(boost::detail::function::function_buffer&, T0, T1)
[with FunctionObj = boost::_bi::bind_t<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T0 = int, T1 = double]’:
.../boost/function/function_template.hpp:913: instantiated from
‘void boost::function2<R, T1, T2>::assign_to(Functor) [with Functor =
boost::_bi::bind_t<boost::_bi::unspecified, void (event_consumer<int,
double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T0 = int, T1 = double]’
.../boost/function/function_template.hpp:722: instantiated from
‘boost::function2<R, T1, T2>::function2(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not::value, int>::type)
[with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T0 = int, T1 = double]’
.../boost/function/function_template.hpp:1064: instantiated from
‘boost::function<R(T0, T1)>::function(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not::value, int>::type)
[with Functor = boost::_bi::bind_t<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T0 = int, T1 = double]’
.../boost/function/function_template.hpp:1105: instantiated from
‘typename boost::enable_if_c<boost::type_traits::ice_not::value,
boost::function<R(T0, T1)>&>::type boost::function<R(T0,
T1)>::operator=(Functor) [with Functor =
boost::_bi::bind_t<boost::_bi::unspecified, void (event_consumer<int,
double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T0 = int, T1 = double]’
.../boost/signals2/detail/slot_template.hpp:156: instantiated from
‘void boost::signals2::slot2<R, T1, T2,
SlotFunction>::init_slot_function(const F&) [with F =
boost::_bi::bind_t<boost::_bi::unspecified, void (event_consumer<int,
double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T1 = int, T2 = double, SlotFunction =
boost::function<void(int, double)>]’
.../boost/signals2/detail/slot_template.hpp:81: instantiated from
‘boost::signals2::slot2<R, T1, T2, SlotFunction>::slot2(const F&)
[with F = boost::_bi::bind_t<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >, R = void, T1 = int, T2 = double, SlotFunction =
boost::function<void(int, double)>]’
test_signal.cpp:15: instantiated from ‘void event_consumer<IntT,
RealT>::consume() [with IntT = int, RealT = double]’
test_signal.cpp:32: instantiated from here
.../boost/function/function_template.hpp:153: error: no match for call
to ‘(boost::_bi::bind_t<boost::_bi::unspecified, void
(event_consumer<int, double>::*)(int, double),
boost::_bi::list2<boost::_bi::value<event_consumer<int, double>*>,
boost::arg<1> > >) (int&, double&)’
--- [/error] ---

Thank you very much for the support!!!

Best,

-- Marco


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