1. ## 4 dimension array

in a 4 dimensional array...

Code:
`char BARRY[1][1][2][2];`
how do I just intialize the last 2 blocks of the array?

example...
Code:
```BARRY[0][0]={{2,3},
{4,5}};```
this is of course on a much lower scale then i need the array...but is there any way to do something similiar to that?

(I hope i explained it well enough...)

2. Magic.

No really -- you can't. You'd have to just set the values individually for that "last block" or set all the values prior as well.

Are you sure you really want a 4-dimensional array, anyways? I can't think of very many times that it would actually make any sense to use one. If some of the dimensions represent concepts (IE a vertex, or a string) then you are most-likely better off making those dimensions objects instead.

P.S. This is my 400th post. Yay.

EDIT: I'm retarded today, don't mind me

3. >char BARRY[1][1][2][2];
What's the point of using an array with one element? As a simple example, here is the equivalent to your array (initialized all nice and pretty):
Code:
```int a[1][1][2][2] = {
{
{
{
1,2
},
{
1,2
}
}
}
};```
Seeing it like this you may notice that the first and second dimensions really aren't doing anything useful except making your code more reader unfriendly. If you remove the useless dimensions you have something much more manageable:
Code:
```int a[2][2] = {
{
1,2
},
{
1,2
},
};```
[Ben Stein Monotone]
Wow.
[/Ben Stein Monotone]

-Prelude

4. Originally posted by Prelude
>char BARRY[1][1][2][2];
What's the point of using an array with one element?
He just made it that small for an example, he said he'd want it bigger later.

5. reason im using the 4 dimension array is for a map...the first two blocks are the x and y coords of the map itself(over 100 maps)

then the last 2 are for each indivudal maps x and y coords...

I was originally trying to do this with a linked list...but i couldnt figure out a good way to link up all the maps...so it seems easier to connect them this way...but i donno...im always up for suggestions ;P

6. Originally posted by Supar
reason im using the 4 dimension array is for a map...the first two blocks are the x and y coords of the map itself(over 100 maps)
There you go right there -- why not make it a class called vertex. Using things like 4-dimensional arrays where sections mean things like vertices makes it unclear what you are trying to model. You're best off notating that concept via objects.

7. Originally posted by Polymorphic OOP
There you go right there -- why not make it a class called vertex. Using things like 4-dimensional arrays where sections mean things like vertices makes it unclear what you are trying to model. You're best off notating that concept via objects.
Exactly, in cases like this it's better to creat a new data type to hold your data.

8. Why make a new class? Sorry im rather new at programming...

I mean why make some new class if Im going to have to go through and define out each map personally anyways?

btw...I still cant seem to figure out how to add data to those end blocks without doing them all right at the beginning or one at a time...=(

thx for all your help tho

9. Originally posted by Supar
Why make a new class? Sorry im rather new at programming...

I mean why make some new class if Im going to have to go through and define out each map personally anyways?
Because it makes logical sense to do so. Taking it down to simpler terms -- an array of vertices that have an x and a y coordinate makes more sense when you define a class that has an x and a y member and make a single dimensional array of those than if you made a 2-dimensional array of ints. It simply doesn't make as much logical sense to have a 2-dimensional array there because what it's modeling isn't as apparent. When you say you want "an array of vertices" then do just that in code -- make a single dimensional array of vertices, each vertex having an x and a y coordinate. Your example is slightly more complex than that but the logic is still the same. Also, defining a class for the vertex allows you to work with member functions that only affect the vertex and you can use it in places where a vertex makes sense and another datatype with 2-ints (ie a vector) wouldn't. All that an array with 2 elements tells you is that there are 2 elements, but there are multiple concepts that can be broken down into a similar fashion (IE point and vector are two different concepts but their makeups are similar).

Originally posted by Supar
btw...I still cant seem to figure out how to add data to those end blocks without doing them all right at the beginning or one at a time...=(

thx for all your help tho
Again, you simply can't.

10. ## Well

You could just create an array of pointers, then that array to another array of pointers, etc.. It wouldn't be as easily managed as a C++ 3rd dimensional array or anything, but you could create a 4th dimensional array that way.

11. I agree with Polymorphic OOP...
I think you should write the class, and post it here so we can help correct mistakes( if there were any ), and you get used to it.

12. i cant seem to figure out this vertex stuff...i looked throughout the forums and google...no real explanations to what you mean...

but anways...since you cant define the whole array except when it is first defined...I cant really make a struct or class for my map arrays...

but i figure that i can just make 1 array for the overall map vector

then make as many others as i need...for the maps....

*shrugs*damn my nubiness ;P