Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!sunic!news.funet.fi!funic!santra!santra!Ari.Huttunen From: Ari.Huttunen@hut.fi (Ari Juhani Huttunen) Newsgroups: comp.lang.c++ Subject: Re: Matrix Class Libraries Message-ID: Date: 19 Mar 91 09:28:01 GMT References: <13505@darkstar.ucsc.edu> <1991Mar18.025539.18998@athena.mit.edu> <1991Mar18.213545.20966@athena.mit.edu> Sender: news@santra.uucp (Cnews - USENET news system) Organization: Helsinki University of Technology, Finland Lines: 35 In-Reply-To: bjaspan@athena.mit.edu's message of 18 Mar 91 21:35:45 GMT In article <1991Mar18.213545.20966@athena.mit.edu> bjaspan@athena.mit.edu (Barr3y Jaspan) writes: >In article , Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes: >|> I think this points out one problem in C++. You really should be able to >|> say: >|> inline double& operator[][](int, int) const; >|> >|> The problem isn't very serious, but it just isn't natural to access array >|> members using notation array(x,y), but array[x][y]. >In this particular case, the first method is preferable. Being able to say >array[x][y] implies (in the conventional C style) that array[x] is meaningful >(it always is in C). If array[] is not defined (array[][] is) then it certainly would be an error to call this undefined member function. So I don't see any problem here. Perhaps it is a religious issue after all. :( > For my Matrix class, it isn't meaningful (you could >argue that I should have derived Matrix from Vector, in which case array[x] >could be meaningful, but that isn't the point.) No, if you did that, there would be some performance penalties or at least I believe so. Correct me if I'm wrong. (If I am indeed wrong, this whole conversation is not needed.) >So if you really always wanted to use [] for array indexing and () only for >function calls, [] would have to accept any number and type of arguments (ie: >operator[](int, int).) But then it would be semantically identical to () >anyway, so what's the point? Well, why do we then have operator[] vs. operator() if if operator() alone would be sufficient? Because operator[] is more clear with arrays. -- Ari Huttunen, email: Ari.Huttunen@hut.fi, phone: 90-7285944