G
Greg
I want to pass a function (testfn) into a another function (fnmeas).
testfn makes use of an object cx, so is it ok to have cx local to the
file containing testfn ? The fnmeas does not care what cx is as such,
but somehow the scope does not seem right.
example
typedef double fn(const double &x);
in fns.cpp..
myclass cx;
double testfn(const double &y)
{
return y*cx.a*cx.b;
}
void go()
{
cx.a = 1;
cx.b = 2;
fn *p = &testfn;
double x = fnmeas(p);
}
in cv.cpp..
double fnmeas(fn *f)
{
return f(1.5) + f(2.5);
}
Is it better to pass a handle of cx to fnmeas ? How would I do that ?
I may be thinking in non OO terms here, but the idea is to have fnmeas
generic.
testfn makes use of an object cx, so is it ok to have cx local to the
file containing testfn ? The fnmeas does not care what cx is as such,
but somehow the scope does not seem right.
example
typedef double fn(const double &x);
in fns.cpp..
myclass cx;
double testfn(const double &y)
{
return y*cx.a*cx.b;
}
void go()
{
cx.a = 1;
cx.b = 2;
fn *p = &testfn;
double x = fnmeas(p);
}
in cv.cpp..
double fnmeas(fn *f)
{
return f(1.5) + f(2.5);
}
Is it better to pass a handle of cx to fnmeas ? How would I do that ?
I may be thinking in non OO terms here, but the idea is to have fnmeas
generic.