[source langg = "cpp"]
const int maxpoints = 250;
const int maxpixels = 5;
point* mousepoints = new point[maxpoints][maxpixels];
allocating multidimensional arrays?
i know how to create an multidimensional array, but not how to allocate it on the heap.
obviusly dosent work.
You cannot allocate multidimensional arrays on the heap (because the first dimension should be fixed). You can use vectors-of-vectors or boost::multi_array in a much easier fashion.
Also, technically, new allocates memory on the free store (the heap is where malloc gets its memory from).
Also, technically, new allocates memory on the free store (the heap is where malloc gets its memory from).
Check the comp.lang.c FAQ.
EDIT: Using "new" = C++ = use STL/Boost.
int **array2 = malloc(nrows * sizeof(int *));array2[0] = malloc(nrows * ncolumns * sizeof(int));for(i = 1; i < nrows; i++) array2 = array2[0] + i * ncolumns;
EDIT: Using "new" = C++ = use STL/Boost.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement