Passing 2D arrays
I have a 2D array of ints, which I wish to pass to a function. I define the function to receive an int**.
When called, the array is cast.
Inside the function, any attempt to access the array results in crashing, even though by displaying the literal address on the screen (in both the called and calling function) it's clear that the address is being recieved correctly.
Accessing the array from main is OK, too.
int** and int (*)[N] are completely different. I like to stay upbeat and avoid being too negative when I describe stuff, but this is one situation where you just can't trick the compiler into being happy. To pass a 2D array, you pass a 2D array or an equivalent type. ie. T (*)[N]. If you want a 2D array of variable size for both dimensions, you need to either simulate a 2D array with a T**, or better yet, use a vector and save yourself a lot of frustration dealing with memory. :) But the methods are not interchangeable.