Q
QH Hong
Compilation of the folowing program gives error message
error C2664: 'solve' : cannot convert parameter 1
from 'double (double)' to 'double (__cdecl *)(double)'
Here's the codes
==== class definition ========
#include "tCls.h"
tCls::tCls()
{
}
tCls::~tCls()
{
}
double tCls::comp1(double x)
{
return x + 1;
}
======== main function =======
typedef double (*function) (double x);
double func1(double x)
{
return x + 2.0;
}
double solve (function f, double x)
{
return f(x) + 3.0;
}
int main(int argc, char* argv[])
{
tCls a;
double t;
t = solve(func1, 1.0);
t = solve(a.comp1, 2.0);
return 0;
}
===============================
How should I define the "function"?
error C2664: 'solve' : cannot convert parameter 1
from 'double (double)' to 'double (__cdecl *)(double)'
Here's the codes
==== class definition ========
#include "tCls.h"
tCls::tCls()
{
}
tCls::~tCls()
{
}
double tCls::comp1(double x)
{
return x + 1;
}
======== main function =======
typedef double (*function) (double x);
double func1(double x)
{
return x + 2.0;
}
double solve (function f, double x)
{
return f(x) + 3.0;
}
int main(int argc, char* argv[])
{
tCls a;
double t;
t = solve(func1, 1.0);
t = solve(a.comp1, 2.0);
return 0;
}
===============================
How should I define the "function"?