B
Ben
Hi,
I have simplified the situation a lot so hopefully this still makes sense...
Say I have a number of functions that work on any individual element of an array. I want to create a function "doOnAll" that
will call ANY of those functions on EVERY element of the array.
e.g.
void doOnAll (int x) {
for (i=0;i<n;i++) {
if (x==0) {
returnValue(i);
} else if (x==1) {
returnIndex(i);
} else if (x==2) {
returnCost(i);
}
}
}
No problem, but say each of the singular functions had different types of arguments instead of all being 'i' as they are above.
I could just pass these on to doOnAll if it's arguments were undefined:
void doOnAll () {
}
But then how would it know which function to call without the variable 'x'?
Can you 'half' specify a functions arguments, say (int x, *)?
Does anyone have any other ideas how to workaround this problem?
Note it may not be obvious why I need to do this but it's related to the equivalent of the 'for' line below in my program
actually being about 100 lines of code, and the structure being a four-dimensional array.
cheers,
Ben C
I have simplified the situation a lot so hopefully this still makes sense...
Say I have a number of functions that work on any individual element of an array. I want to create a function "doOnAll" that
will call ANY of those functions on EVERY element of the array.
e.g.
void doOnAll (int x) {
for (i=0;i<n;i++) {
if (x==0) {
returnValue(i);
} else if (x==1) {
returnIndex(i);
} else if (x==2) {
returnCost(i);
}
}
}
No problem, but say each of the singular functions had different types of arguments instead of all being 'i' as they are above.
I could just pass these on to doOnAll if it's arguments were undefined:
void doOnAll () {
}
But then how would it know which function to call without the variable 'x'?
Can you 'half' specify a functions arguments, say (int x, *)?
Does anyone have any other ideas how to workaround this problem?
Note it may not be obvious why I need to do this but it's related to the equivalent of the 'for' line below in my program
actually being about 100 lines of code, and the structure being a four-dimensional array.
cheers,
Ben C