【问题标题】:no matching function for a function一个函数没有匹配的函数
【发布时间】:2014-10-13 18:37:48
【问题描述】:

我正在尝试对此进行调试,但在这里无法找出问题所在。为什么即使我传递了正确的参数,调用naiveGaussianElimination 时却没有匹配的函数?

void naiveGaussianElimination(int count,float doubleCoefficient[][count+1]){

}

int main() {

/*
 Read from file and assign values to vector
 */

//File stream object
ifstream inputFile;

// store file name
string fileName;

// ask user for the file name and store it
cout << "Enter the file name:>> ";
cin >> fileName;

//Open the txt file
inputFile.open(fileName.c_str());

//search for the text file
if(!inputFile.is_open())
{
    cerr << "Error opening file \n";
    exit(EXIT_FAILURE);
}
else
{
    cout << "File found and successfully opened. \n";
}

/*
 find the number of variables in the equation
 */
int count =0;
string line;
while (getline(inputFile, line)){

    count++;
}
// 2D array to store augmented matrix
float doubleCoefficient [count][count+1];

/*
 assign values from text file to 2D array
 */
float value;
while(!inputFile.eof()){
    for (int i=0; i<count; i++) {
        for (int j=0; j<(count+1); j++) {
            inputFile >> value;
            doubleCoefficient[i][j]=value;

        }
    }

}

// invoke naiveGaussianElimination function
    naiveGaussianElimination(count,doubleCoefficient);

【问题讨论】:

  • doubleCoefficient 未在该代码示例的任何地方定义。另外,我很少使用 C++,但是那个函数签名合法吗?你能发布确切的错误吗?
  • 你从哪里得到你在main 中传递给naiveGaussianEliminationdoubleCoefficient 参数?
  • @slugonamission : 我忘了贴在这里。
  • @TylerGaona:我忘记粘贴了。
  • 我不相信naiveGaussianElimination(int, float doubleCoefficient[][count+1]) 是一个有效的声明。我只需传入一个指向浮点数的指针:naiveGaussianElimination(int, float**)

标签: c++ function multidimensional-array


【解决方案1】:

您必须为多维数组的声明(第一个脚本除外)提供明确的值,因为编译器不知道这里的 count 是什么

void naiveGaussianElimination(int count,float doubleCoefficient[][count+1])
                                                                    ^

试试这样:

    void naiveGaussianElimination(int count,float doubleCoefficient[][4]){
      .....
    }

更多详情请查看:here

【讨论】:

    【解决方案2】:

    **为

    使用动态数组

    //二维动态数组存储增广矩阵**

    float **doubleCoefficient = new float*[count];
        for (int i=0; i<(count+1); i++) {
            doubleCoefficient[i] = new float[count+1];
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-08
      • 2013-05-09
      • 2014-08-16
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多