I have seen this definition of a function that receives a function pointer as parameter:
double fin_diff(double f(double), double x, double h = 0.01) {
return (f(x+h)-f(x)) / h;
}
I am used to see this definition with an asterisk, i.e.:
double fin_diff(double (*f)(double), double x, double h = 0.01);
Do you know why the first definition is also valid?
std::function
. Using templates orstd::function
increases the flexibility by allowing you to pass any kind of callable object with the right signature, like a lambda, functor object, actual function pointer, etc.c
andc++
are two different languages. Please choose one and remove the othertag
as the answer is different depending on the language