C++ multidimensional arrays on the heap

— door Evert Mouw

array picture
Picture of the heap array.

When using C++, you cannot store large arrays in the stack, so you should use the heap memory. You do so by e.g. using the new keyword and using a pointer to the reserved memory in the heap.

Problems emerge when you have to use multidimensional arrays. I could not find elegant solutions that matched my personal taste. For example, see the solutions on Stack Overflow. So here is my solution:

This worked for me and I liked the syntax better than the other solutions, but YMMV.


Facebook Comments