0

在我的 A 和 B 方程中得到这些错误,然后其他错误来自 calcit 的末尾,当我试图将它传递给 slopeit 时

  [错误] 'int [3]' 和 'int [3]' 类型的无效操作数到二进制 'operator*'
 [错误] 'double' 和 'int [3]' 类型的无效操作数到二进制 'operator*'
[错误] 从 'int' 到 'double*' 的无效转换 [-fpermissive]
 [错误] 无法将参数 '2' 的 'int*' 转换为 'double*' 到 'void slopeit (double*,double*, int, double&, double&, double&)'
     double slops[3], yints[3], boards[3];
     double yint15,yint20,yint25,slop15,slop20,slop25,rsq15,rsq20,rsq25;
     double board;

    void calcit (double tim15[], double tim20[], double tim25[], double tem15[],
        double tem20[], double tem25[], int indx, int board,int temperature)
     {
double B;
double A;
double time;
double slopsofslops;
double yofslopes;
double rsq;
double yint15,yint20,yint25,slop15,slop20,slop25,rsq15,rsq20,rsq25;
slopeit(tim15, tem15, indx, slop15, yint15, rsq15);
slopeit(tim20, tem20, indx, slop20, yint20, rsq20);
slopeit(tim25, tem25, indx, slop25, yint25, rsq25);


yints[0]=yint15;               
yints[1]=yint20;
yints[2]=yint25;

boards[0]=15;
boards[1]=20;
boards[2]=25;

slops[0]=slop15;
slops[1]=slop20;
slops[2]=slop25;


indx = 3;


time = pow(e,(temperature -B)/A);
A = (slops * boards) + yofslopes;
B = (yofslopes * boards) + yints; 

//Pass the values needed into writeit and finished 

slopeit(board, slops, indx, slopsofslops, yofslopes, rsq);
       }
  void slopeit(double x[], double y[], int n, double& m, double& b, double& r)
4

4 回答 4

1

C++ 没有任何内置运算符来操作数组,您必须创建自己的重载。

至于最后一个错误,(或指向)int的数组与(或指向)的数组不同double。您必须创建一个新的临时double数组,从数组中填充它int,然后将double数组传递给函数。

于 2013-11-22T18:40:27.977 回答
0

在你对 slopeit() 的调用中,你用 board 而不是 board 调用第一个参数。board 是 double,boards 是 double[]。

于 2013-11-22T18:42:34.873 回答
0

您需要根据您的定义将指针传递给函数

  slopeit(board, slops, indx, *slopsofslops, *yofslopes, *rsq);
       }
  void slopeit(double x[], double y[], int n, double& m, double& b, double& r)
于 2013-11-22T18:46:39.663 回答
0

[Error] invalid operands of types 'int [3]' and 'int [3]' to binary 'operator*'

This error is due to the following line:

A = (slops * boards) + yofslopes;

Both slops and boards are of type double[3]. C++ can't multiply arrays. You'll either need to use a different class that can support it, such as the QVector3D class in the Qt library, or you'll need to calculate the product (either cross product or dot product) in a for loop yourself.

[Error] invalid operands of types 'double' and 'int [3]' to binary 'operator*'

This error is due to the following line:

B = (yofslopes * boards) + yints; 

yofslopes is of type double and boards is double[3]. Similarly, C++ doesn't support doing these kinds of operations. They are incompatible types. You'll probably want to perform a for loop to multiply each element by yofslopes (is what you're after here?). You also can't add one array to another array.

It's unclear what you're trying to do here because here's the unit analysis of that line:

double = (double * 3dVector) + 3dVector

That doesn't make sense...

[Error] invalid conversion from 'int' to 'double*' [-fpermissive]

This error is from the following line:

slopeit(board, slops, indx, slopsofslops, yofslopes, rsq);

You have a global variable called board which is of type double (not double*). Then you defined a local variable (in the parameters of calcit) with the same name, but of type int (not double*). You shouldn't pass in an integer and interpret it as a pointer without explicitly casting it.

[Error] cannot convert 'int*' to 'double*' for argument '2' to 'void slopeit

Not sure what this error is indicating.

Hope this helps!

于 2013-11-22T19:03:51.853 回答