#include
// apply f to arguments x and y, return the result
template
T1 funcall(T1 (*f)(T2,T3), T2 x, T3 y) {
return (*f)(x, y);
}
int prod(int x, int y) { return x * y; }
double power(float f, int i) { return pow(f, i); }
int main()
{
int x = 3; int y = 5;
printf("prod(%d,%d) = %d\n", x, y, funcall(prod, x, y));
float f = 3.5; int i = 2;
printf("power(%g, %d) = %g\n", f, i, funcall(power, f, i));
return 0;
}
|