开发者

calling a 2-dimensional matrix in a function call

while calling and defining a function how to use a 2-dimensional matr开发者_JS百科ix in that function?


C++ doesn't care about bounds, but it needs to compute the memory address given the subscripts (see below). To do this it needs to know the row width (number of columns). Therefore formal 2-dimensional array parameters must be declared with the row size, altho the number of rows may be omitted. For example,

void clearBoard(ticTacToeBoard[][3]) {
   . . .
}

(info from http://www.fredosaurus.com/notes-cpp/arrayptr/22twodim.html)


Use a vector of vectors, for example: std::vector<std::vector<int> >. You can pass this by reference, const or not depending on whether you need to modify the values in the matrix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜