www.digitalmars.com         C & C++   DMDScript  

D - opIndex

reply "Matthew Wilson" <matthew.hat stlsoft.dot.org> writes:
The examples given on the site have the binary opIndex returning a value of
the same type as the second parameter, as in

 struct A
	{
	    int opIndex(int i);
	    int opIndex(int i, int value);
}

Is this so that it can be reused in expressions such as the following

A a1 = ...
A a2 = ...

a1[10] = a2[5] = 3;

I presume the author returns the new value, rather than the previous value?

Matthew
Dec 18 2003
parent "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <matthew.hat stlsoft.dot.org> wrote in message
news:brs079$2n2g$2 digitaldaemon.com...
 The examples given on the site have the binary opIndex returning a value
of
 the same type as the second parameter, as in

  struct A
 {
     int opIndex(int i);
     int opIndex(int i, int value);
 }

 Is this so that it can be reused in expressions such as the following

 A a1 = ...
 A a2 = ...

 a1[10] = a2[5] = 3;

 I presume the author returns the new value, rather than the previous
value? The return type and value from opIndex is whatever the programmer specifies it to be.
Dec 19 2003