why no '->' operator?

Walter Bright newshound at digitalmars.com
Wed Jan 31 22:26:18 PST 2007


Michael Weber wrote:
> 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.length = 1;
> ts[0].a = 3;
> 
> 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;
> 
> It would be easier to just have to do ts[0]->a =3; and be done with it.

TestStruct[]* ts;

declares a pointer to an array of TestStruct. It would be used like:

(*ts)[0].a = 3;

I'm afraid that the -> won't help here, in C++ this would be declared:

TestStruct (*ts)[];

and used like:

(*ts)[0].a = 3;

as well.



More information about the Digitalmars-d mailing list