I gave up on trying to pass a 2d array to a function, where the dimensions are not known at compile time. After some research, it seems like a 2d vector may be a good substitute. I just want to confirm that this is the correct way to declare a 2d vector of dimension totalRows X totalColumns, initializaing each cell to contain the space character:
vector<vector<char> > world(totalRows, vector<char>(totalColumns, ' '));
Your code works. As noticed in the comment,
vector<vector<T>>is not truly a 2D array.The important thing here is that
(totalRows, vector<char>(totalColumns, ' '))and(totalColumns, vector<char>(totalRows, ' '))are equivalent, as long as you always follow the rule used to create the vector:line x column(orcolumn x line)