Re: How does libsigc++ accept member functions?



On Thu, 04 Jun 2009 16:01:33 +0400
Igor Gorbounov <igorbounov topazelectro ru> wrote:
> Daniel Elstner пишет:
> > Am Donnerstag, den 04.06.2009, 15:41 +0400 schrieb Igor Gorbounov:
> >
> >   
> >> Because it looks very ugly,  I'm eager to understand how did you 
> >> bypassed all this stuff using libsigc++?
> >>     
> >
> > The term you are looking for is "PMF" (Pointer to Member Function).
> >   
> 
> It is this very pointer to member function that C++ does not
> allow me to get.
> But those guys from libsigc++ have managed to cope with this problem.
> Though things like "sigc::slot<T_return, T_arg1, T_arg2, T_arg3,
> T_arg4, T_arg5, T_arg6, T_arg7>"
> <cid:part1.08000900.08060503@topazelectro.ru> from documentation look
> discoraging.

Lets say you have a pointer to class object T and a pointer to member
function of such an object:

T* obj;
void (T::*func)();

Once you have assigned values to obj and func you can call the assigned
method on the assigned object with this:

(obj->*func)();

If you store obj and func in a separate class object you have a
callback object which you can dispatch with that call.  If you
templatise the callback class by reference to type of the object
T you have a generic callback object.  If you add futher template
parameters for arguments (if any) to pass to the member function (in
my example there were none) then you have a generic multi-purpose
dispatchable callback object. In libsigc++ such a callback object (a
slot) is created and instantiated by the sigc::mem_fun<> function.

Chris



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