### definition of multi-dimensional array failure

Hi all.

I have a 4 dimensional array declared as such as global:

 `` `` ``char OurShapes[7][4][4][2];``

And it's defined here:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224`` `````` void fillshapes() { OurShapes = { //line { //rotation1 { {0, 0}, {0, 1}, {0, 2}, {0, -1} }, //rotation2 { {0, 0}, {-1, 0}, {1, 0}, {2, 0} }, //rotation3 { {0, 0}, {0, 1}, {0, 2}, {0, -1} }, // rotation4 { {0, 0}, {-1, 0}, {1, 0}, {2, 0} } }, // square { //rotation1 { {0, 0}, {1, 0}, {0, -1}, {-1, -1} }, //rotation2 { {0, 0}, {1, 0}, {0, -1}, {-1, -1} }, //rotation3 { {0, 0}, {1, 0}, {0, -1}, {-1, -1} }, //rotation4 { {0, 0}, {1, 0}, {0, -1}, {-1, -1} } }, // S { //rotation1 { {0, 0}, {0, 1}, {1, 1}, {-1, 0}, }, //rotation2 { {0, 0}, {-1, 0}, {-1, 1}, {0, -1} }, //rotation3 { {0, 0}, {0, 1}, {1, 1}, {-1, 0}, }, //rotation4 { {0, 0}, {-1, 0}, {-1, 1}, {0, -1} } }, // S reversed { //rotation1 { {0, 0}, {1, 0}, {0, 1}, {-1, 1} }, //rotation2 { {0, 0}, {0, -1}, {1, 0}, {1, 1} }, //rotation3 { {0, 0}, {0, 1}, {0, 1}, {-1, 1} }, //rotation4 { {0, 0}, {0, -1}, {1, 0}, {1, 1} } }, // L { //rotation1 { {0, 0}, {0, 1}, {0, -1}, {1, -1} }, //rotation2 { {0, 0}, {1, 0}, {-1, 0}, {-1, -1} }, //rotation3 { {0, 0}, {0, -1}, {0, 1}, {-1, 1} }, //rotation4 { {0, 0}, {-1, 0}, {1, 0}, {1, -1} } }, // L reversed { //rotation1 { {0, 0}, {0, 1}, {0, -1}, {-1, -1} }, //rotation2 { {0, 0}, {-1, 0}, {1, 0}, {-1, 1} }, //rotation3 { {0, 0}, {0, -1}, {0, 1}, {1, 1} }, //rotation4 { {0, 0}, {-1, 0}, {1, 0}, {1, -1} } }, // T { //rotation1 { {0, 0}, {-1, 0}, {1, 0}, {0, 1} }, //rotation2 { {0, 0}, {0, 1}, {1, 0}, {0, -1} }, //rotation3 { {0, 0}, {-1, 0}, {1, 0}, {0, -1} }, //rotation4 { {0, 0}, {-1, 0}, {0, -1}, {0, 1} } } }; }``````

Yet for some reason I get the following error:

Error C2059: Syntax Error : '{'

This error corresponds to the first curly bracket ({) after the line `OurShapes = `

Any ideas?

FYI After that error I have another 99 all to do with this 4D array definition. I can't for the life of me work out what's wrong... any idead?

Mike

P.S. I got a simlar array to work before - but lost the code... :(

Any ideas what I've done?
You're missing the variable name. It shoudl be:
 `` `` ``OurShapes shapes = ``
Afraid that doesn't work...

That just produces the error:
 `` `` ``error C2146: syntax error : missing ';' before identifier 'shapes'``

Besides I'm not declaring a variable type... just the variable itself - Or at leasth I think I am...

Thank you though kbw - at least someone's looking into it with me lol
Mike
Last edited on
Okay, here's an up date:

I've removed the global declaration, and simply declared it in the function it's being defined in.

Example:
 ``1234`` ``````void fillshapes() { char OurShapes[7][4][4][2] = { etc.``````

Problem with this is the array must be global - as soon as this function ends the array falls out of scope and is destroyed. Also for some reason it won't compile even like this without the subscripts informing the compiler how big it is (` char OurShapes[][][][] = `) despite the fact that I was under the impression that Microsoft Visual Studio can work that part out for itself...

Anyway I still have the problem that even if I define the array with a set size for each dimension of the array it still is not global.

How can I overcome this? Can I make a locally declared 4D Array global?

Mike
Sorry, silly mistake. It should be:
 `` `` ``char OurShapes[7][4][4][2] =``
You can not assign values to an array as you were doing in the first your code snip. You may do thiis only then the array is declared that is initialization of an array is allowed only when it is declared.
If you want that it would have new values in a function then you assign values to each element of bthe array in the loop. You may not use the syntax of initialization of array.
Topic archived. No new replies allowed.