簡體   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