Question

Considering this example:

#include <boost/signals2/signal.hpp>
#include <boost/bind.hpp>

typedef boost::signals2::signal< void ( double ) > DoubleSignalType;
typedef boost::signals2::signal< void ( void ) >   VoidSignalType;

class B {
public:
    void connect( DoubleSignalType::slot_type dbl_slot ) {
        dbl_sig.connect( dbl_slot );
    }

    void connect( VoidSignalType::slot_type void_slot ) {
        void_sig.connect( void_slot );
    }
private:
    DoubleSignalType dbl_sig;
    VoidSignalType void_sig;
};

class A {
public:
    void foo( double a ) {};
    void bar( void ) {};
    void other(){
        B b;
        b.connect( boost::bind( &A::foo, this, _1 ) );
    }
};

int main( int argc, char* argv[] ) { return 0; }

When I compile this I get:

g++ x.cpp
x.cpp: In member function ‘void A::other()’:
x.cpp:27:53: error: call of overloaded ‘connect(boost::_bi::bind_t<void, boost::_mfi::mf1<void, A, double>, boost::_bi::list2<boost::_bi::value<A*>, boost::arg<1> > >)’ is ambiguous
x.cpp:27:53: note: candidates are:
x.cpp:9:10: note: void B::connect(boost::signals2::signal1<void, double, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void(double)>, boost::function<void(const boost::signals2::connection&, double)>, boost::signals2::mutex>::slot_type)
x.cpp:13:10: note: void B::connect(boost::signals2::signal0<void, boost::signals2::optional_last_value<void>, int, std::less<int>, boost::function<void()>, boost::function<void(const boost::signals2::connection&)>, boost::signals2::mutex>::slot_type)

Is there a way around?

Was it helpful?

Solution

You have to do something more complicated, because boost::bind's operator() is template, and have arbitrary number of parameters(to be able to call functions with no parameters, as it has some).

If you provide non-overaloaded methods, everything would be ok

OTHER TIPS

One simple solution is to explicitly create the signal type you want. i.e.:

    b.connect( DoubleSignalType::slot_type( boost::bind( &A::foo, this, _1 ) ) );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top