没有功能的匹配功能

时间:2014-10-13 18:37:49

标签: c++ function multidimensional-array

我正在尝试调试此问题,但无法在此处找出问题。为什么即使我已经传递了正确的参数,也没有说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);

2 个答案:

答案 0 :(得分:2)

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

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

尝试这样:

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

有关详情,请查看:here

答案 1 :(得分:0)

**使用动态数组

//用于存储增强矩阵的2D动态数组**

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