TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: BEN CURRY
from: RON BASS
date: 1997-06-19 08:34:00
subject: Re: member functions as arguments

Hello Ben!
 BC>    is it possible to pass member functions as arguments to 
 BC> other functions?
 BC> I have a class called display which has a member function:
 BC>     void xGathercb(FL_OBJECT *, long);
 BC> I need to pass this function as an argument of another function:
 BC>     fl_set_object_callback(FL_OBJECT *, xGathercb, long);
I assume that this second function is not a class member function?  If so, 
the only member function that you can safely pass to it is one declared as a 
static member.
The reason is that non static member functions have an extra parameter in 
their calling list; the pointer to the associated object.  The compiler is 
telling you that if you cast it from a non-static member function to a 
non-member function with a similar looking parameter list, the compiler 
doesn't know what to do about assigning a value for the object pointer.
The problem is similar to declaring a function prototype of
   int foo(long* first, short second, bool third);
and then trying to implement it as
    int foo(short second, bool third)
    {
    '''
    }
 BC> So it is possible to cast from:
 BC>     void (display::*)(blah)
 BC> to
 BC>     void (*)(blah)
It is possible (casts always work) but it wont get the result that you want.
     -Ron  (ron-bass@ti.com)
--- EZPoint V2.2
---------------
* Origin: There's a point here, somewhere... (1:128/13.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.