multidimensional arrays in C/C++ are difficult. i’ve been programming C++ for about ten years now, and i still have trouble getting the syntax right.
you probably don’t actually want to deal with arrays of arrays in raw C++. they’re confusing, which means your code is likely to be buggy, or leaky memory, or just generally not work in subtle ways that might throw you off later down the track. see below for better ways to do it.
but if you really want to use a 2D raw C++ array, the way to do them is to declare this in header file:
then in the constructor:
array_of_arrays = new float*[num_rows];
for ( int i=0; i<num_rows; i++ )
array_of_arrays[i] = new float[num_cols];
and then in your destructor (to avoid leaking memory):
for ( int i=0; i<num_rows; i++ )
the trick is to realise that in C++ an array is actually a pointer to a block of memory that is large enough to contain everything you want. so, eg, when i go
float* array_of_floats = new float;
what array_of_floats will actually be is a pointer to the start of a block of memory that is (sizeof(float)*100+a little overhead) bytes long. and when you ask for array_of_floats what you’re actually saying is, take the memory address of the start of the array_of_floats and add on (20*sizeof(float)) bytes, and then pull the float from out of that memory location.
for example, if sizeof(float) is 4, and array_of_floats points to memory address 0x8000, then array_of_floats will give me the float at memory address 0x8000 + 0x50 (0x50 is decimal 80 in hexadecimal), ie memory address 0x8050.
(you can also say things like
float* my_random_chunk_of_memory = (float*)0x123456;
and then run through printing off everything - you’ll be accessing the data starting at memory address 0x123456 as though it was an array of floats, even though it may be something completely different. and if you go
my_random_chunk_of_memory = 5.0f;
then whatever was at my_random_chunk_of_memory is now overwritten with your new data, which is probably a bad thing, depending on what my_random_chunk_of_memory is supposed to be doing. this is how you make self-modifying code - if you can find the memory address where the machine code for your functions are stored, you can rewrite them on the fly. all sorts of fun can be had this way, but you have to be super l33t to pull it off without making your computer crash.)
back to the question. when you make an array of arrays, what actually happens is that you make an array of pointers to arrays. that’s why you get ugly things like float** for an array of float arrays: ‘float**’ means a pointer to a pointer to a float. in other words, when you ask for an array of arrays, you’re actually asking for a pointer to the first element of a list of pointers to the first elements of a bunch of other lists. at this point i usually start to go crosseyed and think about other ways to deal with things.
so, here’s some other ways:
1- use a 1-dimensional array.
the basic concept is: a 2D array of floats that is 20x20 elements in size has 20*20=400 elements in total; then we can say that  in the 2D array is the same as  in the 1D array, and  is the same as , and  is , and  is , & c. so instead of float my_2d_array, just go my_clever_1d_array , and to access element my_2d_array, just go my_clever_1d_array[5*20 + 15].
this is how pixel data is dealt with in openFrameworks: to access the pixel at (300,50) in an RGB image (which is actually a three-dimensional array), you go
int x = 300;
int y = 50;
int width = my_image.width;
unsigned char* my_image_data = my_image.getPixelData();
// red component
unsigned char red = my_image_data[(width*y + x)*3];
// green component
unsigned char green = my_image_data[(width*y + x)*3 + 1];
2- use a vector of vectors
// declare a vector of vectors (ie, a 2D vector)
std::vector< std::vector<float> > vector_of_vectors;
// add all the rows you want
int row_count = 100;
int col_count = 100;
// allocate room for all the rows
vector_of_vectors.resize( row_count );
// for each row
for ( int i=0;i<row_count; i++ )
// allocate room for all the columns
vector_of_vectors[i].resize( col_count );
// now access like you would in a more script-y language:
vector_of_vectors = 10.0f;
float thingy = vector_of_vectors * vector_of_vectors;
hope this helps