The Operator new With Arrays
Go Up to The new And delete Operators Index
When using the array form of operator new[]()
, the pointer returned points to the first element of the array. When creating multidimensional arrays with new, all array sizes must be supplied (although the leftmost dimension doesn't have to be a compile-time constant):
mat_ptr = new int[3][10][12]; // OK mat_ptr = new int[n][10][12]; // OK mat_ptr = new int[3][][12]; // illegal mat_ptr = new int[][10][12]; // illegal
Although the first array dimension can be a variable, all following dimensions must be constants.