array of function pointer with specific parameter

i need to create a float function pointer array and every function in the array must take a specific set of parameter for example something like
1
2
3
4
5
6
7
8
9
float * input_funct(float inputs[])={
//every function in this pointer array must have parameter of float array
float one(float inputs[]){

},
float two(float inputs[]){

}
}
Last edited on
I'm not exactly sure what you mean. You want to make an array of function pointers that each take in a float array as a parameter and return a float?

This can do that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Example program
#include <iostream>

float one(float inputs[])
{
    std::cout << "hello 1" << std::endl;
    return 1.0f;
}
float two(float inputs[])
{
    std::cout << "hello 2" << std::endl;
    return 2.0f;
}
float three(float inputs[])
{
    std::cout << "hello 3" << std::endl;
    return 3.0f;
}

int main()
{
    float (*my_func_ptr_arr[3])(float[]) = {one, two, three}; // array of function pointers
    
    float input[5] = {0.5f, 1.5f, 2.5f, 3.5f, 4.5f};
    for (int i = 0; i < 3; i++)
    {
        float ret = my_func_ptr_arr[i](input);   
        std::cout << "ret = " << ret << "\n\n";
    } 
}



Last edited on
Is there a reason why you don't use std::vector and std::function.
1
2
3
4
5
6
7
8
9
10
11
12
using FloatVector = vector<float>;
using InputFunction = function<float(FloatVector)>;

float one(FloatVector& fv){}
float two(FloatVector& fv) {}
float three(FloatVector& fv) {}

vector<InputFunction> input_funcs = 
{
  one, two, three  
};
I didnt even think of that thank you.
Topic archived. No new replies allowed.