Boost logo

Boost Users :

Subject: Re: [Boost-users] Beginner question: Why boost::signal creates another instance of the slot object ?
From: Mauricio Gomes (mgpensar_at_[hidden])
Date: 2010-08-20 15:25:07


Hi,

I am still digesting the information. I understand the problem with
lifetime management but when I do:

sig.connect(x);

and x being the listener, I would expect x to be called, not another
instance of X. I will study more what you guys have explained. I hope
at some point it will click on my mind. :)

> As for your initial problem of the receiver being dis-associated from
> the callable, it's probably because it's not properly copyable
I thought the compiler would generate a copy constructor and
assignment operator suitable for S. Is not the case ?

struct S
{
   int x;

   S (): x(0) {}

   void operator () (int i)
   {
       std::cout << "&slot1 = " << this << std::endl;
       x = i;
       std::cout << "slot1.x = " << this->x << std::endl;
   }
};

Thank you !

2010/8/20 Lars Viklund <zao_at_[hidden]>:
> AMDG
>
> As for your initial problem of the receiver being dis-associated from
> the callable, it's probably because it's not properly copyable.
>
> It's normally good form to make things that should not be copied
> boost::noncopyable or otherwise artificially restricted from copying, in
> order to catch such assumptions at an early stage instead of through
> runtime bugs.
>
> --
> Lars Viklund | zao_at_[hidden]
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

-- 
Mau

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