Array-wise operations
Simen kjaeraas
simen.kjaras at gmail.com
Tue Oct 12 13:11:01 PDT 2010
Bob Cowdery <bob at bobcowdery.plus.com> wrote:
> On 12/10/2010 20:29, Simen kjaeraas wrote:
>> Bob Cowdery <bob at bobcowdery.plus.com> wrote:
>>
>>> x_points[]
>>> =(x_average[0]+x_average[1]+x_average[2]+x_average[3]+x_average[4]+x_average[5]+
>>>
>>> x_average[6]+x_average[7]+x_average[8]+x_average[9])/10;
>>>
>>> The average gives me a compile error of incompatible types.
>>
>> You need to append [] to x_average[index].
>>
>>
> Thanks. I tried it the other way round [][0]. To put [0][] seems to me
> the wrong way round. Probably just not understanding the syntax properly.
Yeah, it's a bit the wrong way around, for those coming from C, at least.
The idea is that for any T[] t, t[0] should behave as if a function
returning a T. So, for char[][] c, c[0] returns char[], which would then
be indexed by the next brackets. If index was the function:
c[0][1] => index( index( c, 0 ), 1 );
--
Simen
More information about the Digitalmars-d-learn
mailing list