I have a 4D array and i would like to create a function that i could use to refer to a 2D array inside the 4D array and read its data by appending square braces with indexes to the function call.
int numbers[2][3][4][4] = {
{
{{1,2,3,4}, {4,3,2,1}, {6,7,8,9}, {9,8,7,6}},
{{0,1,0,1}, {1,0,1,0}, {1,1,0,0}, {0,0,1,1}},
{{5,4,1,8}, {4,2,5,1}, {7,2,5,8}, {4,2,5,1}}
},
{ /* same stuff */ }
};
If i wanted to access just {4,2,5,1} for example, i could create a function that returns a pointer to the first int of that array (&number[0][2][1][0]), and access the elements with func()[1], func()[2], func()[3], well... you know that.
int* func() {
return &numbers[0][2][1][0];
}
// func()[2] => 5
But how could i create a function that returns a reference to numbers[0][2], so for example i could do func()[1][0] and it would return 5?
It seems i should work up my understanding of C/C++ pointers, references and arrays, but i will also appreciate "std" and C++11-specific solutions (using some cool std::class over standard arrays). Thanks :)