Sunday, 15 July 2012

linux - C++ unqualified-id, other posts not helping -



linux - C++ unqualified-id, other posts not helping -

i'm working on linux machine , using g++ compile .cpp file. maintain getting next errors:

hillclimbing.cpp:6: error: expected unqualified-id before â[â token hillclimbing.cpp:7: error: expected unqualified-id before â[â token hillclimbing.cpp:8: error: expected unqualified-id before â[â token hillclimbing.cpp:17: error: expected unqualified-id before â[â token

i have been looking @ similar posts on site don't seem match problem, , i'm unable prepare it. here .cpp file:

#include <utility> #include "evaluateparams.h" using namespace std; double[] optimizeparams(evaluateparams eval, pair<double, double> ranges[], double ss[], double a, double e, bool hillclimb, bool ascent); double[] initparams(pair<double, double> ranges[]); double[] climbhill(double pos[], double stepsize[], double epsilon, bool findmax); evaluateparams evalmethod; double accel; //eval/evalmethod: defines method used compare set of params //ranges: list of ranges each parameter can take //ppp: points per parameter, number of points initialized ppa^ranges.size() //hillclimb: indicates weather enact hillclimb algorithm or randomize double[] optimizeparams(evaluateparams eval, pair<double, double> ranges[], double ss[], double a, double e, bool hillclimb, bool ascent){ evalmethod = eval; accel = a; double paramvalues[] = initparams(ranges); if(hillclimb){ paramvalues = climbhill(paramvalues[i], ss, e, ascent); } homecoming paramvalues; } double[] initparams(pair<double, double> ranges[]){ double values[ranges.size()]; for(int j = 0; j < ranges.size(); j++){ double min = ranges[i].first; double max = ranges[i].second; double r = ((double) rand() / (rand_max)); r *= max-min; r += min; values[i][j]=r; } homecoming values; } double[] climbhill(double pos[], double stepsize[], double epsilon, bool findmax){ double candidate[] = [-accel, -1/accel, 0, 1/accel, accel]; while(true){ //may need switch timer in case points stuck double init = eval.evaluate(pos); for(int = 0; < pos.size(); i++){ int best = -1; double besteval = -1 * numeric_limits<double>::max(); for(int j = 0; j < candidate.size(); j++){ pos[i] = pos[i] + stepsize[i]*candidate[j]; double temp = eval.evaluate(temppos); pos[i] = pos[i] - stepsize[i]*candidate[j]; if(temp > bestscore){ besteval = temp; best = j; } } if(findmax){ pos[i] = pos[i] + stepsize[i] * candidate[best]; } else{ pos[i] = pos[i] - stepsize[i] * candidate[best]; } if(candidate[best] != 0){ stepsize[i] = stepsize[i] * candidate[best]; } } if(eval.evaluate(pos)-init < epsilon){ homecoming pos; } } }

and here .h file:

class evaluateparams{ public: evaluateparams(){} virtual double evaluate(double[]); };

most of other posts i've seen fixed adding ';' @ end of header file, i've done.

arrays in c++ declared differently declared in java. moreover, c++ built-in arrays aren't dynamically sized. should replace uses of double[] std::vector<double>: c++ way of specifying dynamically sized array of objects.

c++ linux compilation g++

No comments:

Post a Comment