gpt4 book ai didi

c++ - 将二维数组引入函数c++

转载 作者:行者123 更新时间:2023-11-28 02:24:15 25 4
gpt4 key购买 nike

大家早上好,我知道有很多种形式可以将数组传递给函数,并且有很多关于此的内容。但即使阅读这篇文章,我也无法将我的数组传递给函数。当我在 main 上调用该函数时,出现错误,如以下代码所示。

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int row = 5;
int column=20;
void dimensions (int [20]);

int main (){

int *matriuprova[column];
for (int i= 0; i<column;i++){

matriuprova[i] = new int [row];

dimensions(matriuprova);// <-- here is the error:
//main.cpp:14:31: error: cannot convert 'int**' to 'int*'
//for argument '1' to 'void dimensions(int*)'

}//end of for loop

return 0;
}//end of main

void dimensions (int *matriuprova [20]){
//function code
}

我点击了这个链接: Passing a 2D array to a C++ function

谢谢大家!

最佳答案

您对维度的前向声明有误。

改变

    void dimensions (int [20]);

    void dimensions (int* [20]);

关于c++ - 将二维数组引入函数c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31264322/

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