View Full Version : I doupt it but...


Lord Olleus
Sep 25, 2006, 03:44 PM
... Does anyone here know how to create multidimentional, dynamic arrays in C++? (If you have no idea what I am talking about, don't worry)

I tried this:

float* = MyArray;
MyArray = new float[x][y];

But the compiler told me that I couldn't convert a float (*)[y] into a float*.

I then tried this:

float MyArray[x][y];

But unsuprisingly that didn't work, as the compiler said that the array size had to be fixed at compile time.

I then tried this:

void* = MyArray:
MyArray = new float[x][y]


And that worked. But my compiler then complained when ever I tried to use the array.
I tried to google this and looked through my books, but I couldn't find anything. Anyone here know how to do this?

The Great Apple
Sep 25, 2006, 03:52 PM
If by dynamic you mean with a size set during runtime (it is implied, but just to be sure) then I would do it as follows:

float** MyArray;
MyArray = new float[x][y];

Just because I would do it that way doesn't mean it's the best way of doing it.

Déja
Sep 25, 2006, 03:57 PM
Another option is to use the standard library. You can do vectors of vectors and the like