i trying write program maximizes function, f(x). algorithm is:
double maxx(double(*f)(const double &), double &a, double &b, const double tol = 1e-5) { static double goldenratio = 0.618034; double c = b - goldenratio * (b - a); double d = + goldenratio * (b - a); while (abs(c - d) > tol) { double fc = (*f)(c); double fd = (*f)(d); if (fc > fd) { b = d; d = c; c = b - goldenratio * (b - a); } else { = c; c = d; d = + goldenratio * (b - a); } } return 0.5 * (b + a); } i getting error when call function in main(). error message is:
severity code description project file line error c2572 'maxx': redefinition of default argument: parameter 1
what doing wrong here? put full code here: https://cloudup.com/cqhb_dkdiaf
you're declaring default argument value in function declaration ("prototype") on line 32, and in definition on line 53. reasons unknown me, gods of c++ have decided not allowed: see following excerpt 8.3.6/4 of c++ 2003 standard:
a default argument shall not redefined later declaration (not same value).
note quite old c++ 03 standard -- either compiler you're using still in mode, or behaviour remains unchanged in c++11, or both.
[edit] forgot mention how solve problem! delete default argument every declaration except first.
Comments
Post a Comment