C++ 无效的操作数和类型

标签 c++ arrays binary operands

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

  [Error] invalid operands of types 'int [3]' and 'int [3]' to binary 'operator*'
 [Error] invalid operands of types 'double' and 'int [3]' to binary 'operator*'
[Error] invalid conversion from 'int' to 'double*' [-fpermissive]
 [Error] cannot convert 'int*' to 'double*' for argument '2' to '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)

最佳答案

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

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

关于C++ 无效的操作数和类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20152119/

相关文章:

c++ - 如何从一个文件中读取,然后继续从cin中读取?

C++ const 循环声明

java - 有没有办法在java中用一些初始化的数字创建一个数组,然后向它添加随机数

java - 这是读取充满 double 的二进制文件的好方法吗?

Python 3,将存储二进制数据的字符串转换为 Int

c++ - 动态添加对象?

c++ - 为什么对字符串使用 "\t"而不是 "<press TAB>"?

c - 将输入读入数组

javascript - 需要帮助构建复杂的 JS 对象

algorithm - 图灵机算法