TITLE: operator equivalents PROBLEM: mdeters@cs.bgsu.edu (Morgan Deters) Current "standard" C++ states that operator[] can only be overloaded as a member function (along with operator() and operator->). [ And operator = -adc] Does anyone else find this odd, since it is LEGAL (maybe not _beautiful_, but LEGAL) C and C++ to do this: int i[3]; 1[i]=10; // equivalent to i[1]=10; RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 6 Jul 95 The equivalence relations for the predefined operators do not hold for user-defined operators. For example, given struct S { int i; } *s; the following expressions are exactly equivalent: s->i (*s).i s[0].i But since ->, *, and [] may be independently overloaded, the expressions might mean entirely different things if any of those operators are overloaded. Similarly, (x += y) might not be equivalent to (x = x + y) due to independent overloading. Losing the equivalence of a[i] and i[a] is only one more example. One of the major reasons for requiring certain operators to be member functions is to prevent type conversion on the first parameter (the object). Such conversions would usually have unintended results for those operators, where they were not ambiguous.