where:
nonlinear_sys_pressure(args) & nonlinear_sys_gibbs(args) are functions returning long doubles and accepting an array of long doubles
args[3] & hbar[2] are long double arrays
template <typename T, typename U, typename V>
T dn_dxn(int n, T (*f)(U[]), V args[], int narg)
{
if (n == 0)
return f(args);
else
{
T h;
if (sizeof(T) == 128)
h = std::pow(args[narg] * std::sqrt(LDBL_EPSILON), 1 / n);
elseif (sizeof(T) == 64)
h = std::pow(args[narg] * std::sqrt(DBL_EPSILON), 1 / n);
else
h = std::pow(args[narg] * std::sqrt(FLT_EPSILON), 1 / n);
T sum = 0;
for (int k = 0; k <= n; k++)
{
args[narg] += (n / 2 - k) * h;
sum += std::pow(-1, k) * nCr(n, k) * f(args);
args[narg] -= (n / 2 - k) * h;
}
return sum / std::pow(h, n);
}
}
However, in my new case, I'm receiving an error that "template argument/substitution failed: mismatched types 'T (*)(V*)' and 'long double'"
I can tell this is an issue with the function pointer, but I've had no problems with it in my previous work. What's going on?
the type of the expression nonlinear_sys_pressure(args) is longdouble, so it can't be used as the first argument to renew_hbar, which expects a T (*f)(U[]).
You'd have to use nonlinear_sys_pressure (or &nonlinear_sys_pressure if you want to be explicit about pointer formation)
That was the problem. I tried including the arguments in the function pass. I had it right before and just could see it. I've been staring at this code too long. Thank you!