Boost logo

Boost Users :

Subject: Re: [Boost-users] Beginner question: Why boost::signal creates another instance of the slot object ?
From: Lars Viklund (zao_at_[hidden])
Date: 2010-08-20 15:53:14

On Fri, Aug 20, 2010 at 04:25:07PM -0300, Mauricio Gomes wrote:
> > 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 ?
> --
> Mau

The synthesised cctor and op= will do a member-wise copy and
assignment, respectively.

If you have value members, the copy or target will contain copies of

If you want to share state between two instances, you need to have
reference members, reference_wrapper members or pointer-type members.

Like say:

struct S1
        shared_ptr<int> x;


struct S2
        boost::reference_wrapper<int> x;

Lars Viklund | zao_at_[hidden]

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