How to dynamically create a c++ array with known 2nd dimension? -
i have function:
void foo(double[][4]); which takes 2d array 2nd dimension equal 4. how allocate 2d array can pass function? if this:
double * arr[4]; arr = new double[n][4]; where n not known compiler. cannot compile. if use generic 2d dynamic array, function foo not take it.
as asked, best use typedef
typedef double four[4]; 4 *arr; // equivalently double (*arr)[4]; arr = new four[n]; without typedef more cryptic
double (*arr)[4]; arr = new double [n][4]; you should consider using standard containers (std::vector, etc) or containers of containers though.
Comments
Post a Comment