A thought on pointers
Tesuji
Tesuji_member at pathlink.com
Mon Jun 19 18:54:46 PDT 2006
For pointers, using * and & for dereferencing seems ugly, a more interesting
syntax could be:
A* aPtr;
A instanceA;
to point aPtr to instanceA, instead of
<code> aPtr = &instanceA; </code>
write
<code> aPtr -> instanceA; </code>
and it reads "aPtr points to instanceA". This frees the pointer syntax up from
the * & operators,
Using this syntax, one can eliminate the need for the dereferencing operator
(*), and use pointers directly with operators etc, i.e.
int i1, i2, i3;
int* p1, p2, p3;
p1 -> i1;
p2 -> i2;
p3 -> i3;
p3 = p1 + p2;
And this has the same effect as i1 = i2 + i3;
This would largely simplify the coding for containers, and allow a custom
container to do things like
myVector[3]++;
provided that the opIndex operator for MyVector returns a pointer. Also makes
the pointer behave much like C++ reference types.
More information about the Digitalmars-d
mailing list