我想接下来要运行的代码,我得到无效的错误类型对于j循环内:无效类型数组
for(int i = 0; i < N; i++) //steps
{
j[i]=0;
for (int j = 0; j < Particles; j++) //Particles
{
u = randnum(0,1);
dr = pow(pow(a, 1-alph) + u * (1-alph)/B, 1/(1-alph));
phi[j] = randnum(0,M_PIl);
pre_x = x [j];
pre_y = y [j];
x[j] = pre_x + cos(phi[j]) * dr;
y[j] = pre_y + sin(phi[j]) * dr;
while((sin(A * x[j]) + Delta * sin(C * x[j])/2) * h + H < y[j])
{
u = randnum(0,1);
dr = pow(pow(a, 1-alph) + u * (1-alph)/B, 1/(1-alph));
phi[j] = randnum(0,M_PIl);
x[j] = pre_x + cos(phi[j]) * dr;
y[j] = pre_y + sin(phi[j]) * dr;
}
j[i] = j[i] + cos(phi[j]);
}
myfile<<j[i]<<endl; //Outputs array to txtFile
}
myfile.close();
我检查的其他问题与类似的标题,但标题不匹配对我来说。错误确切的说法是:
invalid types ‘int[int]’ for array subscript
j[i] = j[i] + cos(phi[j]);
j是一个整数。你不能用它作为数组。你得到一个错误,因为它是错误的。 –
看起来你有两个不同的东西,都命名为'j' - 一个数组(其代码中没有显示其声明)和一个循环索引。给他们不同的名字。 –
什么是'j'声明为外环之前?该信息将解释错误消息。 – Peter