我正在編寫一些基本的矩陣函數,並得到一個錯誤,我無法弄清楚如何診斷。聲明的變量或字段(函數)void
我在我的.h文件中的函數:
void matrixMultiplication (int arr1[][100], int arr2[][100], int a1row, int a2col, int targetArr[][100]);
在我.cpp文件我有:
void matrixMultiplication (matrix1, matrix2, rowOfMatrix1, columnOfMatrix2, finalMatrix);
其定義爲
void matrixMultiplication (int arr1[][100], int arr2[][100], int a1row, int a2col, int targetArr[][100]) {
for (int a = 0; a < a1row; a++) {
for (int b = 0; b < a2col; b++) {
for (int c = 0; c < a2col; c++) {
targetArr[a][b] += arr1[a][c]*arr2[c][b];
}
}
}
}
一切聲明這裏:
//designates the sizes of both matrices
int rowOfMatrix1 = 0;
int columnOfMatrix1 = 0;
// size of matrix 1 = rowOfMatrix1 x columnOfMatrix1
int rowOfMatrix2 = 0;
int columnOfMatrix2= 0;
// size of matrix 2 = rowOfMatrix2 x columnOfMatrix2
//arrays that hold the values of the integers in the matrices
int matrix1 [100][100];
int matrix2 [100][100];
int finalMatrix [100][100];
然而,當我運行程序時,我得到以下錯誤:
In function 'int main()' [Error] variable or field 'matrixMultiplication' declared void
我看到這個問題以前有人問,但答案必須用繩子,裏面什麼都沒有做我的程序做,我無法弄清楚如何將這個答案擴展到這種情況。
爲什麼你指定返回類型,當你調用* *的功能? –
在一個不相關的說明中,我希望你在調用之前的某個地方初始化'finalMatrix',否則你將會有*未定義的行爲*。 –