parameterized function

Hi everyone,

I am using a C++ library to simulate some physics. In order to do some batch processing, I need to generate automatically an array of function pointers or a parametrized function. Here is what I am doing:

1
2
3
4
5
6
7
8
9
bool exampleFunc (double x, double y, double z){
 return {x <= 2 && x >= 1}
}

int main{
 Solid exampleSolid = new FuncSolid(exampleFunc);
 void simulate(exampleSolid);
 return 0;
}


where FuncSolid is the library class. I want to do a lot of these simulations with different functions controlled by a parameter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
typedef bool (*FuncSolidPointer) ( double x, double y, double z );

FuncSolidPointer Functions[100];

for (int i = 0; i < 100; i++){
 bool exampleFunc (double x, double y, double z){
  return {x <= 2 + i/100 && x >= 1}
 }
 Functions[i] = exampleFunc;
}

int main{
 for (int i = 0; i < 100; i++){
  Solid exampleSolid = new FuncSolid(Functions[i]);
  void simulate(exampleSolid);
  return 0;
 }
}

This would be easy, if I could just add an argument to the FuncSolid constructor, but the class is defined in the library does not expect an additional parameter. I tried to change that, but this affects a lot of other classes.
I know that I cannot place a for statement where the code is not executed but since none of the solutions I thought of work I have to use wrong code to show what I want to do. Does anyone have an idea how to do that?

Thanks in advance,

Daniel

It would also be helpful if someone would confirm that this is not possible!
Last edited on
Maybe create your array statically, e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bool exampleFunc1 (double x, double y, double z}
{
...
}

bool exampleFunc2 (double x, double y, double z)
{
...
}

typedef bool (*FuncSolidPointer) ( double x, double y, double z );

// create and initialise global array of function pointers
FuncSolidPtr funcarray[100] = 
{
  &exampleFunc1,
  &exampleFunc2,
  ...
};


I think this should work
Topic archived. No new replies allowed.