I'm trying to make a pointer point to a 2D array of pointers. What is the syntax and how would I access elements?
C++ – How to Allocate a 2D Array of Pointers
allocationc++multidimensional-arraypointers
allocationc++multidimensional-arraypointers
I'm trying to make a pointer point to a 2D array of pointers. What is the syntax and how would I access elements?
Best Answer
By the letter of the law, here's how to do it:
Be careful to delete the contained pointers, the row arrays, and the column array all separately and in the correct order.
However, more frequently in C++ you'd create a class that internally managed a 1D array of pointers and overload the function call operator to provide 2D indexing. That way you're really have a contiguous array of pointers, rather than an array of arrays of pointers.