Image

Imagespl wrote in Imagecpp

Passing functions

I want to keep an array of pointers to functions.

The following code works:
#include
[Error: Irreparable invalid markup ('<iostream.h>') in entry. Owner must fix manually. Raw contents below.]

I want to keep an array of pointers to functions.

The following code works:
#include <iostream.h>
#include <stdio.h>

int min(int x, int y)
{
if (x < y)
return x;
return y;
}

void main()
{
int (*fun)(int, int) = &min;


cout << fun(2,3) << endl;
getchar();
}


What doesn't work: I have an array called moveFunctions that I want to store pointers to a move-function for each player (numPlayer players). So, I need an array of function pointers.

I have a class with:
void * (*moveFunctions)(int&, int&, int &, int &); // This compiles

Then later on I say:
moveFunctions = new void *[numPlayers];

This does not compile, I get the error:
'=' : cannot convert from 'void **' to 'void *(__cdecl*)(int&,int&,int&,int&)'

Anyone know the propper syntax? I've tried everything.