Re: [sigc] Generic member functors
- From: klaus triendl <klaus triendl eu>
- To: libsigc-list gnome org
- Subject: Re: [sigc] Generic member functors
- Date: Sun, 11 Jan 2009 23:48:55 +0100
JinXXXX Kili Billl schrieb:
Hello,
I have been trying to use sigc++ library to make a kind of a generic
member functor, but I didn't succeed.
Basically, I would like to create a functor, to which I would be able
assign arbitrary member functions of any class derived from a previously
chosen base class. I tried this, but with not much luck. I am attaching
a simple example where I would like to show what exactly I mean.
I hope that something like this is possible with sigc++.
I have also come across several ambiguities with sigc++, which are
commented in the source file. I don't understand the behavior of sigc++
there, and I marked these spots, so you can look at them.
There are no ambiguities with sigc++. There are templates involved, so
you can't e.g. assign a mem_functor typed for a child to a mem_functor
typed for a Parent. And I think you are mixing slots and functors...
A slot represents a callable entity, no matter what functor is behind.
So, a slot is the generic functor you want to have (only knowing about
the return type and parameters, but loosing compile-time information
about the original functor).
What you want to do is the following:
<code>
Parent p;
Child c;
sigc::slot<int, Parent*, int, double, char> myclosure;
myclosure = sigc::mem_fun(&Parent::f);
const int ret1 = myclosure(&p, 0, 1.0, 'c');
myclosure = sigc::mem_fun(&Child::g);
const int ret2 = myclosure(&c, 0, 1.0, 'c');
</code>
Klaus Triendl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]