error: template argument/substitution failed: mismatched types 'T (*)(V*)' and 'long double'

I'm early in my work with templates. I've gotten a few to work, so I thought I understood them. However, this one is giving me some trouble.

Trying to call the following function (namespaces removed for length)

renew_hbar(nonlinear_sys_pressure(args), nonlinear_sys_gibbs(args), args, hbar);

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

The associated template is:
1
2
3
4
5
6
7
8
template <typename T, typename U, typename V, typename W>
void renew_hbar(T (*f)(U[]), T (*g)(U[]), V args[], W hbar[])
{
    hbar[0] = hbar[0] - (a_i(f(args), g(args), args) + b_i(f(args), g(args), args));
    hbar[1] = hbar[1] - (c_i(f(args), g(args), args) + d_i(f(args), g(args), args));

    return;
}


I've previously succeeded in passing function pointers and arguments in a similar manner:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
        else if (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 long double, 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)

Last edited on
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!
Topic archived. No new replies allowed.