Newsgroups: comp.lang.c++ Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!ahodgson From: ahodgson@athena.mit.edu (Antony Hodgson) Subject: Re: Matrix Class Libraries Message-ID: <1991Mar19.225851.3521@athena.mit.edu> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: <1991Mar18.213545.20966@athena.mit.edu> Date: Tue, 19 Mar 91 22:58:51 GMT Lines: 31 In article Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes: >In article <1991Mar18.213545.20966@athena.mit.edu> bjaspan@athena.mit.edu (Barr3y Jaspan) writes: stuff about whether matrices should be indexed by (x,x) or [x][x]. > >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.) > My matrix class overloads [] to return a Vector&. Because of the way my code is structured, there's no performance penalty (bounds checking takes place, but that has to happen anyway). The only problem is that someone outside the class can change the size of the Vector returned. I'm not sure I can avoid that and still allow the elements of the vector to function as LHSides (i.e., Vector overloads [] to return a double& so that individual elements can be changed). I suppose one could derive a class ProtectedVector privately from vector and disallow size-changing operations on it; Matrix [] could then return a reference to a protected vector. Tony Hodgson ahodgson@hstbme.mit.edu