Boost logo

Boost :

From: graham.shanks_at_[hidden]
Date: 2002-10-15 05:11:07

Doug Gregor wrote:
>> Dirk Gerrits wrote:
>> >I'd use this:
>> >
>> >sig.connect( boost::ref(eventCounter) );
>> >
>> >That way, a reference to your original object should get connected instead
>> >of a copy, so the output of your test program should be 1.
>> Unfortunately boost::ref returns a boost::reference_wrapper<T>, whose
>> operator() returns a T*, which doesn't match the requirements of a slot.
>boost::reference_wrapper<T> is a special case for Boost.Signals (just as
>it is for Bind, Lambda, and Function) that asks those libraries to use a
>reference to an existing object instead of making a copy.

Got it. Unfortunately Dirk's suggested code fails to compile for me (MSVC 6.0
SP5) giving the following error message:

c:\Projects\Tools\3rd Party\boost_1_29_0\boost/signals/slot.hpp(68) :
error C2440: 'return' : cannot convert from 'struct EventCounter' to
'const class boost::reference_wrapper<struct EventCounter> &'

Reason: cannot convert from 'struct EventCounter' to
'const class boost::reference_wrapper<struct EventCounter>'
No constructor could take the source type, or constructor
overload resolution was ambiguous
c:\Projects\Tools\3rd Party\boost_1_29_0\boost/signals/slot.hpp(104) :

Looking at slot.hpp it appears to correctly determine that we're passing a
reference to the object. However I don't quite understand how the function that
is failing is supposed to work

template<typename F>
const F& get_inspectable_slot(
            const F& f,
{ return f.get(); }

Here the template parameter, F, is of type boost::reference_wrapper<T>.
Therefore f.get() returns a T&, which we are then trying to convert back to a
boost::reference_wrapper<T>. This ties in with the compiler diagnostic.

What am I missing here?

Graham Shanks

Boost list run by bdawes at, gregod at, cpdaniel at, john at