In my program I have the need to copy 2d arrays of lengths array[3][8] and array[3][3]. Because of the way I have had to set my parameters I haven't been able to do this in one function so I instead have 2 currently.
void copyArray(float arrayA[][8], float arrayB[][8])
{
for (int a = 0; a < 3; a++)
{
for (int b = 0; b < 8; b++)
{
arrayA[a][b] = arrayB[a][b];
}
}
}
void copyArray(float arrayA[][3], float arrayB[][3])
{
for (int a = 0; a < 3; a++)
{
for (int b = 0; b < 3; b++)
{
arrayA[a][b] = arrayB[a][b];
}
}
}
Is there a way to condense this into one function instead of having these 2 very similar functions?
std::vectororstd::array. If you are stuck using raw arrays, pass the dimensionsaandbseparately, then you can have a single function for any shaped array.std::vectororstd::array), it could be done by makingcopyArraya templated function (where the template arguments issize_tfor the dimensions).memcpy?