Quote:Original post by donjonson
cool the "pretend" 2D array sounds like the easiest to implement Ill try that.
Thanks
This is what Fruny meant with giving up the 2D-ness - you no longer get the syntax you'd like, but it's always possible to treat a 1D array as 2D, by simply doing manually what the compiler would normally do for you (since true "2D arrays" will be stored in a single chunk of memory that basically gets addressed like a 1D array).
Mike's way (which you reprised, minus the deletion code - do remember that your deletes need to exactly balance your news) will give you the syntax you want, at the expense of some runtime overhead. It will also have different semantics: the array is no longer necessarily "rectangular" - you are responsible for keeping it so. That is, in your inner loop to allocate each "line", there's nothing requiring you to keep NUMOFCHUNKS (the "line length") constant. Each is handled as a separate array, which is pointed at from the original int**. Depending on your application, this could be good, bad, or mostly irrelevant.
You should also see
here.