没有与calculateSum匹配的函数调用

No matching function call for calculateSum

本文关键字:函数调用 calculateSum      更新时间:2023-10-16

我正在编写一个打印NxN数组的程序,并使其工作。但是,我还必须创建一个void函数来查找原始数组中子数组的总和。

第一个数组:

0 1 2 3 
4 5 6 7
8 9 10 11

函数数组必须输出:

8 12
20 24

我现在的问题是一个错误,"没有匹配的函数调用calculateSum。"任何帮助都将非常感激!!感谢您花时间阅读这篇文章。

#include <iostream>
#include <math.h>
#include <cstdlib>
#include <string.h>
#include <iomanip>
void calculateSum(int **arrays, int size ) ;
using namespace std ;
int main() {
    int *number, i, j, *n, counter = 0 ;

    cout << "Enter a value for a  n*n array: " ;
    cin >> *number ;
    *n = *number ;
    int array[*number][*number] ;
    cout << "This is the first array:  " << endl ;
    for (i = 0 ; i <= (*n - 1)  ; i ++) {
        for(j = 0 ; j <=  (*n - 1) && counter < ((*n)*(*n)); j ++, counter ++){
             array[i][j] = counter ;
             cout << setw(6)<< array[i][j]  ;
        }
    cout << endl ;
}
calculateSum(array, *number ) ;
return 0 ;
}
void calculateSum(int **arrays, int *size ) {
int **newLand ;
for(int i = 0; i < *size ; i++) {
    newLand[i] = new int[*size];
for(int j = 0; j < *size ; j++) {
          newLand[i][j] = arrays[i][j] + arrays[i][j+1] + arrays[i+1][j] + arrays[i+1]     [j+1]; //equation to add the numbers
 }
 }

声明和定义之间的类型不匹配。对于您的使用,我建议在两个地方都使用int,因为它表示大小并且没有被更改。这样就不需要在函数体中反复解引用指针。

void calculateSum(int **arrays, int size);
...
calculateSum(&array, number);
...
void calculateSum(int **arrays, int size) {