A program has both the big picture and the details. It is a good strategy to divide the whole into smaller logical subtasks. However, the detail that you are now asking seems to depend on the big picture.
There is an operation that you want to do. It requires data. The data should be in suitable data structures. The operation involves algorithms. The algorithms use that data and thus interact with the data structures. The structures and the algorithms have to be compatible and support each other. There are many ways to choose them.
What makes you think that the
func
has to have those particular parameter types? You know the problem that the program should solve.
For example, what is the range of valid values that are stored in the
x
? Why are
px
and
py
global variables in such minimal example?
how can I send n to func in line 20 to get sets of two dimensional arrays? |
You do show the implementation of func() and thus reveal that it does not "give" 2D arrays. It merely operates on existing arrays. Less than that; it uses one 2D point as index to retrieve exactly one value from array y and copies it to both coordinates of one 2D point of list u. The func does not return any value, yet you try to pass something to a ostream.
Too much guessing.
I'll rewrite that example, but this is equally incomplete and nonfunctional:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
const size_t BAR = ...;
struct Point {
int x;
int y;
};
Point func( const Point & a, const int b[][BAR] ) {
const int c = b[a.y][a.x];
Point d { c, c };
return d;
}
int main()
{
const int N = 10;
Point x[N] {};
int y[BAR][BAR] {};
Point u[N]
for (int n=0; n < N; ++n) {
u[n] = func( x[n], y );
}
return 0;
}
|
The loop on lines 20-22 updates the u just like your example does (with the exception that your main() does not have array u).