Computer Science Canada Initializing A Multidimensional Array |
Author: | drij [ Wed Oct 22, 2008 12:51 pm ] | ||
Post subject: | Initializing A Multidimensional Array | ||
This code will not run:
I have no idea what's wrong with it. I think that I should be able to initialize this array but I get the error: 'init' value is the wrong type. |
Author: | The_Bean [ Wed Oct 22, 2008 1:12 pm ] | ||
Post subject: | Re: Initializing A Multidimensional Array | ||
Your declaring your array wrong, the "of array" only needs to be a ",".
|
Author: | [Gandalf] [ Wed Oct 22, 2008 2:12 pm ] |
Post subject: | RE:Initializing A Multidimensional Array |
The_Bean is right, however the way you are currently declaring the array could work too. After all, multidimensional arrays are just arrays of arrays. The problem is, you have a const that needs to be initialized prior to run time. You would have to explicitly use an array where each element is another array. |
Author: | Tony [ Wed Oct 22, 2008 2:44 pm ] |
Post subject: | RE:Initializing A Multidimensional Array |
The syntactical difference is my_array(1)(2)(3) vs. my_array(1,2,3). The advantage to array of array declaration is that you could get a full array as the result; the latter use requires access to a particular int1. Although this type of access is not always necessary. |
Author: | drij [ Wed Oct 22, 2008 4:24 pm ] |
Post subject: | Re: Initializing A Multidimensional Array |
Thanks guys. The_Bean's solution worked. I suppose initializing a multidimensional array declared the way had mine at the top would require the values to be specified differently. Assuming it's even possible. ![]() P.S.: In case you're wondering; this was for a tick-tac-toe game; storing all eight possible combinations of three squares that all would need to be of the same type for the game to have been won. |