why no '->' operator?

Lionello Lunesu lionello at lunesu.remove.com
Wed Jan 31 22:12:37 PST 2007


"Michael Weber" <mweber1488 at gmail.com> wrote in message 
news:eprugq$2t6g$1 at digitaldaemon.com...
>I have used D for a few months now and its the best thing I have found 
>since C++. However, there are a number of things that bother me about D. I 
>am not getting into all of them just my qualms about the arrow operator. I, 
>for one, do not see a reason why it was not included. Here is a reason why 
>it should be included:
>
> struct TestStruct {
>        int a,b;
> }
> TestStruct[]* ts;

ts is a pointer to a dynamic array!

> ts.length = 1;
> ts[0].a = 3;

ts[0] *is* an array, not an element. In fact, ts[0] is an array that doesn't 
exist.

> The dot operator is supposed to resolve the structure pointer and assign a 
> to be three but this wont compile because the compiler thinks that a is a 
> property of arrays and not a member of the structure. Instead I have to do 
> this:
>
> (*ts[0]).a = 3;

Here, the array is dereferenced, which is the same as [0], so this line can 
be written as ts[0][0].a
This actually refers to an element, so "a" is known now.

> It would be easier to just have to do ts[0]->a =3; and be done with it.

There's no point for having ->, the compiler can always know whether you 
mean -> or .
In your case, the code just makes no sense, which is why it can't tell :)

L. 





More information about the Digitalmars-d mailing list