Boost logo

Boost Users :

Subject: Re: [Boost-users] Beginner question: Why boost::signal creates another instance of the slot object ?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-08-19 20:29:20


Mauricio Gomes wrote:
> Thank you very much Steven, boost::ref worked fine.
> Just for my education, what is the rationale behind making a copy of
> the signaled object ?
> It seems odd to me since the object interested in receiving the event
> ends up not receiving it (unless we use boost::ref).

Passing function objects by value is the normal
convention in C++. There are many cases where
it is the correct behavior. For example, if you
you connect a function object created by boost::bind
to the signal, the function object is a temporary and
is destroyed immediately. If it were stored by
reference, the boost::signal would be left with
an invalid reference. Don't think of the function
object as the object receiving the signal. The
function object is an action to be performed.

> I am obviously missing something conceptually here. If you or anyone
> could explain it to me I'd really appreciate.

In Christ,
Steven Watanabe

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