gpt4 book ai didi

C++ unqualified-id,其他帖子没有帮助

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:46 25 4
gpt4 key购买 nike

我在 linux 机器上工作并使用 g++ 编译 .cpp 文件。我不断收到以下错误:

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

我一直在查看此站点上的类似帖子,但它们似乎与我的问题不符,而且我无法修复它。这是 .cpp 文件:

#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 to compare a set of params
//ranges: list of ranges that each parameter can take
//ppp: points per parameter, the number of points initialized is ppa^ranges.size()
//hillClimb: indicates weather to enact the hillClimb algorithm or simply 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);
}
return 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;
}
return values;
}

double[] climbHill(double pos[], double stepSize[], double epsilon, bool findMax){
double candidate[] = [-accel, -1/accel, 0, 1/accel, accel];
while(true){ //may need to switch to a timer in case points get stuck
double init = eval.evaluate(pos);
for(int i = 0; i < 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){
return pos;
}
}
}

这是 .h 文件:

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

};

我看到的大多数其他帖子都是通过添加“;”来修复的在头文件的末尾,我已经完成了。

最佳答案

数组在 C++ 中的声明方式与在 Java 中的声明方式不同。此外,C++ 内置数组不是动态调整大小的。您可能应该替换所有对 double[] 的使用通过 std::vector<double> : 这是指定动态大小的对象数组的 C++ 方法。

关于C++ unqualified-id,其他帖子没有帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24274457/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com