Multi dimensional array question.
Simen kjaeraas
simen.kjaras at gmail.com
Sun Jul 11 01:25:06 PDT 2010
dcoder <gtdegamo at yahoo.com> wrote:
> I'm wondering why in D if you declare a fixed multi dimensional array,
> you
> have to reverse the index order to access an element. I know it has
> something
> to do with how tightly [] bind, but the consequence is that it seems so
> different to other languages, it makes it error prone.
The idea is that T[] is an array of T, for any T. if T == int[3], T[]
would be int[3][]. Also, for indexing, given T[] arr. arr[i] peels off
the first layer, giving you a T.
If arr[i] used the first set of brackets, generic functions would be
thoroughly borked, as a T passed to a template as int[3] would lead to
different indexing from a T of int.
--
Simen
More information about the Digitalmars-d-learn
mailing list