Hello all,
I need to code a program where a function pointer '*fun1' is delivered as
input of function 'foo1'.
In standard C, 'foo1' is correct but foo2 gives the same result without
syntax error. I don't know whether 'foo2' is correct in C++.
Thank you for reading through it all and trying to help!
Gang-Gyoo JIN
-----------------------------------------
#include <stdio.h>
#include <math.h>
void foo1(float &x, float (*fun)(float x)){
x= x+(*fun)(x);
}
void foo2(float &x, float fun(float x)){
x= x+fun(x);
}
float fun1(float x){
return exp(-x);
}
void main(){
float x1= 0.0, x2= 0.0;
for(int j= 0; j < 10; j++) {
foo1(x1, fun1);
foo2(x2, fun1);
x1+= 0.1;
x2+= 0.1;
printf("%f %f\n",x1,x2);
}
}