Re: [sigc] Re: [Boost-users] Signals & Slots



Am 08.01.2005 12:34:15 schrieb(en) Murray Cumming:
On Sat, 2005-01-08 at 06:05 -0500, Carl Nygard wrote:
> On Sat, 2005-01-08 at 09:23 +0100, Murray Cumming wrote:
> > On Fri, 2005-01-07 at 20:10 -0500, Carl Nygard wrote:
> > > sigc::connect() -- can it take a function object or
ptr-to-function or
> > > must they be wrapped with sigc::ptr_fun() or sigc::mem_fun()?
> >
> > You can use a pointer-to-function without using sigc::ptr_fun().
I
> > tested that just now.
> >
> > A pointer-to-member-function without sigc::mem_fun() would be
useless
> > without the object instance.
>
> Yeah, but it can assume operator()() if given the address of a
class
> object instance, in the case of a function object.  That's what I
meant
> by "function object ... without... sigc::mem_fun()"?  Is that
supposed
> to work, or is the explicit sigc::mem_fun() required?

Yes, this works:

class foo
{
  public:
  void operator()(int i)
  {
    std::cout << "foo(int "<< i << ")" << std::endl;
  }
};

int main()
{
  sigc::signal<void, int> sig;

  foo instance;
  sig.connect(instance);

  sig.emit(1);
}


Again, I am surprised. I'm not sure whether I like it, but I guess
people should be less surprised as they get used to functors.

This is fully intended. Apart from function pointers, signal::connect is meant to take any functor object and convert it into a slot object implicitly.

Regards,

 Martin





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]