没有与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) {
相关文章:
- 函数调用中参数的顺序重要吗
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 变量没有改变?通过向量的函数调用
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 模板函数调用
- 获取从C++中同一类中的构造函数调用的方法返回的值
- 析构函数调用
- 成员函数调用和C++对象模型
- 使用共享指针的函数调用,其对象应为 const
- C++:编译时检查匹配的函数调用对?
- 函数调用C++中的参数太少
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- 返回指向对象的指针的函数调用是否为 prvalue?
- C++ 如何重载 [] 运算符并进行函数调用
- 代码的效率. 转到和函数调用
- 是同一作用域的函数部分中的函数调用
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 类型擦除的std::function与虚拟函数调用的开销