Hi! How can I Passe some part of multi-Dimensional Array to a Function; for example only two dimension of three dimension of a an array with 3 dimension. This is because my function is defined for working with 2 dimension arrays.
With built-in arrays, for any a[K][M][N], the expression a[x] is a 2D array (because 3D array is, quite literally, an array of 2D arrays)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
template<std::size_t R, std::size_t C>
void print2D(int (&a)[R][C])
{
for(auto& row: a) {
for(int n: row)
std::cout << n << ' ';
std::cout << '\n';
}
}
int main()
{
int a[3][3][3] = {};
print2D(a[1]);
}
but if you want some arbitrary 2D slice (e.g., a[x][1][[y]), you will need an array library that offers views such as boost.multi_array (or write your own array class, std::valarray gives an easy way to do it)