Archive of the Gamebuino Classic forum (2014-2018), rebuilt from the pages kept by the Wayback Machine: only part of the topics and pages were captured. Read-only. Removal on request: hi@gamebuino.com.
can i make a function array with pointers?
REGFly Wed Jun 24, 2015 9:43 pm
The question is pretty straightforward. I recently came back from a huge break because of exams and now i'm resuming my snake game, but i can't remember how to do this, if i ever even knew how to do this :lol:
This is what i wrote:
but it dosen't work
This is what i wrote:
- Code: Select all
int const * menuChoice[] =
{
singleGame(),
multiGame(),
classicGame(),
changeSettings(),
gameCredits(),
terminate(),
};
but it dosen't work
awesome101 Wed Jun 24, 2015 10:02 pm
Yeah you can. This is some code for a simple c++ program.
#include <iostream>
using namespace std;
typedef int (*IntFunctionWithOneParameter) (int a);
int function(int a){ return a; }
int functionTimesTwo(int a){ return a*2; }
int functionDivideByTwo(int a){ return a/2; }
void main()
{
IntFunctionWithOneParameter functions[] =
{
function,
functionTimesTwo,
functionDivideByTwo
};
for(int i = 0; i < 3; ++i)
{
cout << functions[i](8) << endl;
}
}
#include <iostream>
using namespace std;
typedef int (*IntFunctionWithOneParameter) (int a);
int function(int a){ return a; }
int functionTimesTwo(int a){ return a*2; }
int functionDivideByTwo(int a){ return a/2; }
void main()
{
IntFunctionWithOneParameter functions[] =
{
function,
functionTimesTwo,
functionDivideByTwo
};
for(int i = 0; i < 3; ++i)
{
cout << functions[i](8) << endl;
}
}
REGFly Thu Jun 25, 2015 1:27 pm
And if my functions dont take anything or return anything could i declare it like this?
Typedef void (*arrayFunction);
Typedef void (*arrayFunction);
Myndale Sun Jul 19, 2015 6:56 am