Boost logo

Boost :

From: Brunen, Johannes (jbrunen_at_[hidden])
Date: 2002-08-08 03:18:12


Hi Doug,

first thank for instantly reply. I need some additional advise.

You wrote:

> You'll want to use boost::signal0<XVOID>::slot_type instead of
boost::signal0<XVOID>::slot_function_type.
> Otherwise, bad things will happen if you are expecting automatic
connection lifetime management to work.

I changed my code to use boost::signal0<void>::slot_type and to use the bind
call:

class X
{
public:
        void Connect(boost::signal0<void>::slot_type f);
private:
        boost::signal0<XVOID> _signal;
};

void X::Connect(boost::signal0<XVOID>::slot_type f)
{
        _signal.connect(f);
}

class A
{
        void somefun(X& x);
public:
        void f ();
};

A::somefun(X& x)
{
        x.Connect(boost::bind(&A::f, this));
}

This works pretty fine. However, when I tried to use a slot functor defined
in class A it doesn't compile anymore:

class A
{
        void somefun(X& x);
public:
    struct SlotFunctor
    {
        SlotFunctor(A& a) : _a(a) {}
        void operator() () const
        {
            _a.f();
        }

        A& _a;
    };

private:
    SlotFunctor _slot;
};

A::somefun(X& x)
{
        x.Connect(_slot);
}

It produces the following error on MS VC++ 6.5:

..\..\..\..\Comp\Boost\boost/signals/slot.hpp(97): error C2664:
'boost::reference_wrapper<A::SlotFunctor const>
boost::signals::detail::slot_base::get_invocable_slot(const A::SlotFunctor
&,boost::signals::detail::signal_tag)': cann
ot convert parameter 2 from 'boost::signals::detail::value_tag' to
'boost::signals::detail::signal_tag'
        No constructor could take the source type, or constructor overload
resolution was ambiguous

Using boost::signal0<void>::slot_function_type works either for this as for
the function case with the bind call.

Would you be so kind to clarify the usage of slot_type, slot_function_type
and of the automatic connection
lifetime management a little bit for me? I would like to properly use the
signals library.

With kind regards

Johannes


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk