gpt4 book ai didi

c++ - 声明为 void 的变量或字段(函数)

转载 作者:行者123 更新时间:2023-11-30 03:46:52 25 4
gpt4 key购买 nike

我正在编写一些基本的矩阵函数,但遇到了一个我无法确定如何诊断的错误。

我的 .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

我看到之前有人问过这个问题,但答案与字符串有关,这与我的程序无关,我不知道如何将这个答案扩展到这种情况。

最佳答案

请尝试从下面的行中删除 void 并重新编译。它应该可以解决问题。

void matrixMultiplication (matrix1, matrix2, rowOfMatrix1, columnOfMatrix2, finalMatrix);

调用函数时,不应给出返回类型。这就是编译器提示的原因。

关于c++ - 声明为 void 的变量或字段(函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33932592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com