Mail Archives: djgpp/1999/04/27/22:10:49.2
Ofer Nave wrote:
> >2) How do I make a pointer to a class function and call it using that
> >pointer?
> This is a C++ question, not a DJGPP question, but the answer is that you
> can't take the pointer of a member function unless it is a static member
> function. See the following:
That is incorrect. This compiles under DJGPP and shows how to take the
address of a non-static member function and call it. Please note that you must
explicitly pass the object to the function. There are some warnings which can
be removed with casts, but this runs and prints what you would expect "static
\n myMember bb = 42". And if you feel it is too much to separetly take care of
the function pointer and the object pointer, just stick them in a struct, and
make a #define which will call it correctly.
#include <stdio.h>
class foo
{
public:
int bb;
void myMember( void ) ;
static void myStaticMember( void ) ;
} ;
void foo::myMember()
{
printf("myMember: bb = %d", bb);
}
void foo::myStaticMember()
{
printf("static\n");
}
void main( void )
{
void (*ptr)() ;
void (*a)(foo&);
foo bar = {42};
a = bar.myMember ;
ptr = bar.myStaticMember ;
ptr();
a(bar);
}
--
(\/) Endlisnis (\/)
s257m AT unb DOT ca
Endlisnis AT BrunNet DOT Net
Endlisnis AT HotMail DOT com
ICQ: 32959047
- Raw text -