Boost logo

Boost Users :

Subject: [Boost-users] Using boost.signals with boost.bind
From: Sergey Kishchenko (voidwrk_at_[hidden])
Date: 2008-10-13 08:25:00


I have one problem with boost.bind and boost.signals I can't understand.
Source code is the best description, therefore

#include <iostream>
#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>

class Func : public boost::noncopyable
    void operator()(int i)
        std::cout<<"Func::operator("<< i <<")\n";

typedef boost::signal<void ()> signal_type;
Func f;
signal_type::slot_type binded_func = boost::bind<void>(boost::ref(f),42);

int main()
    boost::shared_ptr<signal_type> apSig(new signal_type());

    apSig.reset(new signal_type());
    boost::signals::connection con = apSig->connect(binded_func);
    std::cout<<"Connected: "<<con.connected()<<" Blocked:

Program output:

Connected: 0 Blocked: 1

Ie, if i create new signal and then try to connect to the same slot, it
fails. If I use not boost::bind object but only boost::function as slot, all
works ok. I can not understand, why?
I used Boost 1.34.1, gcc 4.1.2

Sergey Kishchenko

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at