View Single Post
Storing an array of function calls, and their params.....
Old
  (#1)
Maleficus
Member
 
Maleficus's Avatar
 
Status: Offline
Posts: 1,054
Join Date: May 2004
Location: Planet Earth
Default Storing an array of function calls, and their params..... - 16-05-2005

Lets say I have a struct that looks somewhat like in this example (note, this is just example code, its not put here as compilable/logical code):

Code:
typedef struct
{
	int		foo;
	int (*fooFunc) (int *param1, int *param2);
} my_func_t;

my_func_t *func_array[64];

Now, in a function in the code, I want to loop thru and fill that array with different functions and params, so that I can just call them by reference later.

i.e.

Code:
my_func_t *callerFunc;
int i = 0;
char *myChar;
while (i < 64)
{
	callerFunc = func_array[i];

	if ( i == 1)
	   callerFunc->fooFunc = MyCoolFunc(12, 13);
 
   if (i == 2)
	   callerFunc->fooFunc = MyCoolFunc(44, 22);


//   ETC, ETC, ETC......
 
   i++;
}

int MyCoolFunc( int parameter1, int parameter2) {

// CODE GOES HERE
}
Now, later I want to loop thru "func_array" and just call the function that was passed to it, and its parameters.

I haven't gotten as far as calling the function pointer again tho, I'm just in the part where I save the array of functions, and get this warning:

warning C4047: '=' : 'int (__cdecl *)(int ,int )' differs in levels of indirection from 'int '


I'm sure its something simple, but its bugging me. :o


Dum Spiro Spero


  
Reply With Quote