How to pass variables with a table of pointers to functions

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to pass variables with a table of pointers to functions

1,823 Views
mjcoury
Contributor I
I have the following table of pointers to functions

int (* HeaderFunctions[])()= {
processHeaderGPAAM,
processHeaderGPALM,
processHeaderGPAPA,
.....
}


and then the following code to call the function

iError = HeaderFunctions[i]();//Jump to Parse Function

I took this from a book that used it as an example but they did not need to pass a variable .. and I am trying to avoid using a global (no particular reason) do i put the variables I would pass in the () that are currently blank?

Thanks
Labels (1)
0 Kudos
1 Reply

193 Views
CrasyCat
Specialist III

Hello

Well in that case you have to change the type of the table.

Instead of defining a table of pointer to functions with no parameters returning an int, define a table of pointer to functions with an int parameter returning an int for example.

This is done as follows:

int (* HeaderFunctions[])(int)= {
processHeaderGPAAM,
processHeaderGPALM,
processHeaderGPAPA,
.....
};

For sure all functions should use the same type of parameter in that case.

I hope this helps.

CrasyCat

0 Kudos