Does anybody know how member of function can be a pointer to a function. The following example crashes when I call the member that is pointing to a function.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
typedef long fooPtr(char *);
typedef struct
{
fooPtr *func;
long cnt;
} MyStruct;
/******************************************************************************/
long func(char * str)
{
printf("%s\n", str);
return -1;
}
/******************************************************************************/
void main(int argc, char *argv[])
{
MyStruct *ex;
long l = 0;
ex = (MyStruct *)malloc(sizeof(MyStruct));
if ( ex == NULL )
printf("malloc failed");
ex->cnt = 99;
l = ex->func("Hello"); // crashes here
free(ex);
return;
}
Thanks
Rass