编译错误-数组下标的类型'char [int]'无效 [英] Compile error - Invalid types 'char[int]' for array subscript

查看:113
本文介绍了编译错误-数组下标的类型'char [int]'无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个执行矩阵数学运算的程序.幸运的是,代码逻辑不是给我错误的原因.

I'm working on a program that does some matrix math. Fortunately the code logic is not what is giving me the errors.

我正在使用以下代码来输出存储在二维数组中的矩阵:

I am using the following code to output a matrix that is stored in a 2-d array:

void ouputMatrix(char arr[], int matrixRows, int matrixColumns) {

for (int a=0; a<matrixRows; a++) {
    for (int i=0; i<matrixColumns; i++) {
        cout << arr[a][i] << " ";
    }
    cout << endl;   
}
cout << endl;
}

但是,当我尝试编译此代码时,会被告知:

However when I try to compile this code, I am told:

在函数'void outputMatrix(char *,int,int)'中:[错误]数组下标的类型'char [int]'无效.

"In function 'void outputMatrix(char*, int, int)': [Error] Invalid types 'char[int]' for array subscript.

错误类型向我提示,我缺少有关c ++数组语法的明显内容或类似内容,但我无法弄清楚.我在做什么错了?

The error type suggests to me that I am missing something obvious with regards to c++ array syntax or something like that but I cannot figure it out. What am I doing wrong?

推荐答案

问题是我试图将多维数组传递给函数,但使用的语法与1-d数组相同.由于数组的大小为100(根据我的问题,这是您不知道的大小,抱歉……)传递它的正确方法是:

The issue was that I was trying to pass a multidimensional array into the function but used the same syntax as I would for a 1-d array. Since the array has a size of 100 (which isn't something you could know based on my question, sorry...) the correct way to pass it is:

void ouputMatrix(char arr[][100], int matrixRows, int matrixColumns);

这篇关于编译错误-数组下标的类型'char [int]'无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆