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}
};