c++ - Referenzen-array

Ich wounder wie ich kann, damit dieser code funktioniert?

#include <iostream>
using namespace std;

void writeTable(int (&tab)[],int x){
    for(int i=0;i<x;i++){
        cout << "Enter value " << i+1 <<endl;
        cin >> tab[i] ;
    }
}


int main(void){
    int howMany;
    cout << "How many elemets" << endl;
    cin >> howMany;

    int table[howMany];
    int (&ref)[howMany]=table;
    writeTable(ref,howMany);
    return 0;
}

Und hier sind die Fehler, die ich habe:

|4|error: parameter tab includes reference to array of unknown bound int []’|
|18|error: invalid initialization of reference of type int (&)[]’ from expression of type int [(((unsigned int)(((int)howMany) + -0x00000000000000001)) + 1)]’|
|4|error: in passing argument 1 of void writeTable(int (&)[], int)’|

Danke für die Hilfe

  • C++ nicht haben VLA.
  • Sie könnte verwenden std::vector
InformationsquelleAutor John | 2010-10-16
Schreibe einen Kommentar