Does someone know how the signature of a function pointer looks? I need that for passing a function address as an argument.
Here is my non-working attempt:
1 2 3 4 5 6 7 8
double add( double a, double b) { return a + b; }
double mul( double a, double b) { return a * b; }
// here I don't know how the signature should be look
double calc( (double *oper_ator)(double, double), double a, double b)
{
return oper_ator( a, b );
}
double calc(double (*parameter_name)(double, double), double a, double b)
Consider using a type alias:
1 2 3
// pointer to function returning double accepting two doubles
using math_fn = double(*)(double, double);
double calc(math_fn f, double a, double b) { return f(a, b); }