Given the title of this post, I think the issue you are asking about is the fact that C++ only supports a single array dimension for dynamic allocation.
You can allocate an array of constant sized arrays, though.
1 2 3 4 5 6 7 8
void Test(int n)
{
constint c = 10;
int (*field2)[c] = newint[n][c];
delete [] field2;
}
int** does not work in this case.
If you need to define 2 or more dynamic dimensions, you could allocate a one dimensional array and then calculate the offset yourself. In this case I would define a little array class with a SetAt(int, x, int y), etc methods (you can get operator[] to behave like a normal array, but I don't think it's worth the extra effort).
Andy
P.S. I had to check the syntax for the array pointer; I would use the array class myself.
First, Don't define NULL twice. It's already defined when you include <iostream>. If you're using VC++ 2010, it's recommended that you use nullptr. Second, you declare 2 variables, n and m, which remain uninitialized (you should get a warning from your compiler regarding this) which you use later on. Thirdly, you create a 2-dimensional array of characters. Since you release the resources allocated by field as soon as they're allocated, you waste time and resources.
Andy, line 5 of your code gives me error. int (*field2)[c] is a pointer to an array of c integers. A pointer to an array cannot directly allocate resources. Instead, it must point to an array that's allocating resources. Also, you never check if n is a valid integer.
Some companies, esp. in the financial sector, like to avoid "cutting edge" technology; they let everyone else sort out the teething troubles before switching to the new version. So I'm trying to keep coding in C++ from coding in C++0x well separated for the time being.
I have gcc installed, as well as Visual Studio 2008, so I can explore bits of C++0x with that.
By the way, I've never used the trick in the fragment I posted in real code, or even though of doing so. I have just played about with it, after I sat the syntax mentioned somewhere on the web.
But it seems pretty useless as you cannot pass (e.g.) a int *()[2] via a char** param. So I'm left wondering why this particular syntax works. The behaviour of Vsual C++ 2010 suggests that maybe it's a bit of a mistake that it does.