Thomas Fischer
Thomas Fischer

Reputation: 590

boost signals2 - error when pass a slot to disconnect

I want to pass a slot to disconnect like in the boost signals2 documentation:

Pass slot to disconnect: in this interface model, the disconnection of a slot connected with sig.connect(typeof(sig)::slot_type(slot_func)) is performed via sig.disconnect(slot_func).

#include <iostream>
#include <boost/signals2.hpp>

class Test {
public:
    Test();
    using Signal = boost::signals2::signal<void ()>;
    void slot();
    void test();
};

Test::Test() {
    boost::function<void ()> boundSlot = boost::bind(&Test::slot, this);
    Signal sig;
    sig.connect(Signal::slot_type(boundSlot));
    sig();
    sig.disconnect(boundSlot);
};

void Test::slot() {
    std::cout << "slot()" << std::endl; 
};

int main()
{
   Test aTest;
   return 0;
}

... but I got an error when calling disconnect (see http://cpp.sh/45q6):

error: ambiguous overload for 'operator=='
(operand types are 'boost::signals2::slot >::slot_function_type {aka boost::function}'
and 'const boost::function')

What do I wrong?

Upvotes: 1

Views: 1060

Answers (1)

ForEveR
ForEveR

Reputation: 55887

Problem is, that std::function has no operator == for function compare, only for function and nullptr, but it's required, so you just can use boost::function, which has compare operator and boost::bind.

Upvotes: 1

Related Questions