samedi 28 décembre 2019

How to create a 2D array in C++?

OK, this question seems to be silly but bear with me. When I trying to create a 2D array in C++, it gave me a warning (len is an integer):

double a[len][len];
// warning: variable length arrays are a C99 feature
// warning: variable length array used

So I tried another:

double **a = new double[len][len];
// error: only the first dimension of an allocated array may have dynamic size
// read of non-const variable 'len' is not allowed in a constant expression

How can I do it correctly?

Aucun commentaire:

Enregistrer un commentaire