Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c++ Subject: Re: Declaration of multi-dimensional arrays. Message-ID: <7449@haddock.ima.isc.com> Date: 14 Sep 88 16:53:56 GMT References: <8809032205.aa09007@PARIS.ICS.UCI.EDU> <8166@alice.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 28 In article <8166@alice.UUCP> bs@alice.UUCP (Bjarne Stroustrup) writes: >[Douglas C. Schmidt asks about providing multi-dimensional arrays via >overloading the subscript operator instead of the function-call operator] > >I think that an array with multiple dimentions, such as a Fortran >a(1,2,3), or a C++ array accessed (through a dope-vector or something) >using an overloaded operator(): a(1,2,3), is different in several >ways from the C array you get by repeated use of subscripting v[1][2][3]. Certainly. And a `+' meaning string concatenate is different from the `+' meaning integer add. But it can still be convenient to use the same symbol. (In fact, I might want to overload *both* a[1,2,3] and a(1,2,3) with different semantics, for some classes where this would make sense.) >On the other hand, overloading operator[] to take more than one >``sunbcript argument'' runs into a problem with C. a[1,2,3] is >perfectly legal C and C++ (provided a is of a suitable type). I don't find this a compelling argument. I doubt that any serious program uses this `perfectly legal' feature, and little would be lost if it had to be written a[(1,2,3)] to force the comma operator. (This is analogous to the situation for function calls.) To keep the grammar simple, this should apply to all uses of the [] operator, overloaded or not. I'll bet allowing `a[1,2,3]' would break less code than changing the meaning of `int f();' did. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint