How does one do this? (or, better stated, what is the typical way of doing this in cp?)
Yes, I’ve looked on Stack Overflow, but it seems that the methods given either use hardcoded dimensions or require extra work to get it into the proper input. (like making the 2d array into a bunch of pointers to pointers.)
The only way that seems promising is using a template argument, but it doesn’t seem to work for variable sizes… (unless I’m doing something wrong.)
Code
(p is just a macro for getting an int from input.)
template <int rows, int cols>
void arr(int (&array)[rows][cols])
{
cout<<array[0][0]<<endl;
}
int main() {
fast;
int r = p;
int c = p;
int test[r][c];
arr(test);
return 0;
}