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

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -