data containers

torhu no at spam.invalid
Thu Jul 3 15:46:54 PDT 2008


Moritz wrote:
> So now I have a two dimensional array ready for my classes, but sadly, I 
> cant find any information on how classes can be stored in a 
> multidimensional array and how I can use the instances stored there.
> 
> Ive just guessed and typed:
> 
> int add_element(ScreenElement new_element, uint layer)
> {
> 	if(layer <= layer_count)
> 	{
> 		ScreenElement[] single_layer = layer_map[layer];
> 		single_layer ~= new_element;
> 	}
> 	else
> 	{
> 		writefln("cant insert ScreenElement into non existing layer");
> 	}
> 	return 0;
> }
> 
> Sadly, this doesnt work, I get an Error: ArrayBoundsError upon inserting.
> Can anyone tell me how this is done, and maybe even where I can find 
> usful examples for more cmplex uses of arrays in D?
> 
> My biggest problem ATM is the lack of good tutorials or examples, it 
> seems that D is no easy language to get started with, once you want to 
> do more than basics :-(


Does it work if you make this change?

- 	if(layer <= layer_count)
+ 	if(layer < layer_map.length)


More information about the Digitalmars-d-learn mailing list