Q: Dynamic assignment of two-dimensional array of methods: cxjddd author: cxjddd Thank: Michaelgs, IICUP, XPDavis, NJSEEWHY, GoodLuckYXL, HXBLVC, Flood1984, Kobefly, Somedummy review: Steedhorse Community Correspondence Post: View A: Several methods of dynamically assigned a two-dimensional array dynamic allocate two-dimensional array, a lot of methods, here I talk about what I think. Different methods can be treated in different ways of two dimensions of the two-dimensional array. First, two dimensions are fixed: this is the simplest, as follows: // a bit confusing method: int (* a) [m] [n]; //m, n is constant a = new int = 1] [10 ] [20]; // Why do you want this? Delete [] a; // typedef method, but the same confusion type_two [10] [20]; array_two * a = new array_two [1]; // still "one-dimensional" delete [] a;, This is a little failed. This is still like this: (* a) [m] [n], or a [0] [m] [n], is this still two-dimensional? There is no way, only otherwise think. // Deta, the statement seems to be less than one-dimensional type_1 int (* a) [n]; a = new int [m] [n]; a [var_m] [var_n] = 0; delete [] A; this seems good It is only one dimension when the declaration is declared, but it is simple, the same is true. Second, only one-dimensional fixation: If there is only one dimensional fixed, two forms: [M] [N] and [M] [N], the latter is simpler. For N fixed, we can use this: // [m] [n] type type_2 int (* a) [n]; a = new int [m] [n]; a [var_m] [var_n] = 0; delete [] a; this looks very similar to Type_1, and compares the two-dimensional array as a function of the parameter transmission, the first dimension is not important. Look at New, the type of out is int (*) [n]. For [M] [N], you can exchange the subscript, you can use Type_2, it is true. If you insist on [M] [N], look at what method.
// [m] [n] type, direct method TYPE_3 INT * a [M]; for (int i = 0; i -------------------------------------------------- ------------ // [m] [n] type, improve TYPE_4 INT * a [M]; a [0] = new int [m * n]; for (int i = 1; i