How to pass a 2D array as a parameter?

The C++ way of handling bool arrays has my brain hurting.

I have an array of bool arrays in certain permutations as a fixed constant that I want to copy from. In C# this is as simple as saying…

bool[][] thing = new bool[][] {{true, true, true, true}, {false, false, false, false}; 
bool[] thing2; 
thing2 = thing[1];

And thing2 would output 4 falses.

C++ does like doing it this way so I’m trying to build a function that takes from A and copies one element at a time to B and I’m stuck on trying to get the passed in correctly.

My function is setup like so

void CopyArray(bool *a[16][4], bool *b[], int index){
	for(int i = 0; i < 4; i++){
		b[i] = a[index][i];
	}
}

And the compile error says error C2664 void CopyArray(bool *[][4],bool *[],int)': cannot convert argument 1 from 'bool [16][4]' to 'bool *[][4]'

I wish I knew where to start to make sense of this. Without the array size in the parameters for variable a I get a compile error that says missing subscript. I know that means that 2D arrays must have a width defined… but in this case of passing in something that already exists, isn’t it defined then when it takes its argument? I don’t want to use a fixed size for the 2D array parameter because what if I want any size 2D array?

This is the array in question I want to copy an array from.

bool switchTable[16][4] = {
	/* Bnt:  Red    Blue   Green  Yellow */
	/* Swh:  One    Two    Three  Four   */
	/* 1  */ {true,  false, false, false},
	/* 2  */ {false, true,  false, false},
	/* 3  */ {false, false, true,  false},
	/* 4  */ {false, false, false, true },
	/* 5  */ {true,  true,  false, false},
	/* 6  */ {true,  true,  true,  false},
	/* 7  */ {true,  true,  true,  true },
	/* 8  */ {false, true,  true,  true },
	/* 9  */ {false, false, true,  true },
	/* 10 */ {true,  false, true,  true },
	/* 11 */ {true,  true,  false, true },
	/* 12 */ {false, true,  true,  false},
	/* 13 */ {true,  false, false, true },
	/* 14 */ {true,  false, true,  false},
	/* 15 */ {false, true,  false, true },
	/* 16 */ {false, false, false, false}
};

simple as you send 1D array, address of array.
foo(&arr);

As you’ve discovered, in C++, arrays declared as type[] are a quite hairy, and you should certainly not use them with the new keyword. Instead use a TArray or a TArray>. If we were outside of the Unreal Engine, it would be correct to use a std::vector or std::array.

I watched a C++ tutorial video on Visual Studio and that guy favored normal arrays over std::vector. There seems to be debate over what type of array should be used.

I also wanted to add another solution I discovered to this. I kept switchTable as a static normal array because that’s data that never ever changes but I need to reference the the combination of bools at [x][0]. Instead of trying to copy it C# style, I better understand how to use a pointer to get what I want.

bool *FourElemetArray;
FourElementArray = &swtichTable[index][0];

Then I just deference that pointer.