|
Boost Users : |
Subject: [Boost-users] Using boost.signals with boost.bind
From: Sergey Kishchenko (voidwrk_at_[hidden])
Date: 2008-10-13 08:25:00
Hi,
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
{
public:
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->connect(binded_func);
(*apSig)();
apSig.reset(new signal_type());
boost::signals::connection con = apSig->connect(binded_func);
std::cout<<"Connected: "<<con.connected()<<" Blocked:
"<<con.blocked()<<"\n";
}
Program output:
Func::operator(42)
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
Regards,
Sergey Kishchenko
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