Originariamente inviato da effe_89
progetto442.cpp|33|error: 'y' cannot appear in a constant-expression|
...
m[index].data=new int[x][y];
...[/CODE]
Vi faccio notare l'errore...
...e due possibili soluzioni:
codice:
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int *array, x, y;
cin>>x;
cin>>y;
array = new int [x*y];
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
array[i*x+j] = (i*10) + j;
for(int i = 0; i < x; i++) {
for(int j = 0; j < y; j++)
printf("%0.2d ", array[i*x+j]);
cout<<endl;
}
delete[] array;
int **array2 = new int*[x];
for(int i = 0; i < x; i++)
array2[i] = new int[y];
for(int i = 0; i < x; i++)
for(int j = 0; j < y; j++)
array2[i][j] = (i*10) + j;
for(int i = 0; i < x; i++) {
for(int j = 0; j < y; j++)
printf("%0.2d ", array2[i][j]);
cout<<endl;
}
for(int i = 0; i < x; i++)
delete[] array2[i];
delete[] array2;
return 0;
}