challenging 1-line question


I am using a function like this:
double f (double M, void *l)
{
f_params &params= *reinterpret_cast<f_params *>(l);
return (log(1./((interpol(M)) * params.G_F)));
}

I am calling this function in the main program like

f (14, ?)
I don't know what to write in the ? space. I am using,

f_params &params= *reinterpret_cast<f_params *>(l);

so that I may recall the value of params.G_F which is in a loop in the main program that is i am changing the value of params_G_F in a loop. But I am not getting how to write this function in the main program as I don't know what to write for '?'
Should be one of those:
1
2
3
f_params Data;
// Initialize Data
f(14, &Data);


1
2
f_params * pData = /* Initialize */ ;
f(14, pData);


You can also choose to pass in an actual f_params pointer or variable:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Pointer
double f(double M, f_params * param)
{
    return (log(1./((interpol(M)) * param->G_F)));
}
// call it like you did before.

// Const Reference
double f(double M, const f_params& param)
{
    return (log(1./((interpol(M)) * param.G_F)));
}
// Call it like:
f_params Data;
f(M, Data);
Last edited on
Topic archived. No new replies allowed.