繁体   English   中英

将数组传递给函数的C ++问题

[英]C++ problems passing array to function

我有以下代码:

#include <iostream>
using namespace std;

int recursivefunction(int NbProducts, int NbPlates, int prevlevel, int currentlevel,     int thearray[] ) {
currentlevel = (prevlevel + 1);
if(prevlevel = 0) { currentlevel = 1; }  //only ensures that the FIRST run has no issues with negatives
while(thearray[currentlevel] < (NbProducts - NbPlates + 1)) {
    if(currentlevel = NbPlates) {
        cout << thearray[currentlevel] << endl;  //debug, do something to test full program
        }
        else recursivefunction(NbProducts, NbPlates, prevlevel, currentlevel, thearray[] );
    }
}
int main() {
int NbProducts = 10, NbPlates = 3, prevlevel = 0, currentlevel = 0;
int thearray[100];
recursivefunction (NbProducts, NbPlates, prevlevel, currentlevel, thearray[]);
}

并且一直给我“ thearray中的']'之前的期望值。忽略程序的其余部分,它现在什么也不做。如果我在那些括号内给出一个值,则会给我很多其他错误,有什么想法吗?

当您调用该函数时,它应该不带数组本身传递[]

recursivefunction (NbProducts, NbPlates, prevlevel, currentlevel, thearray);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM