home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-cv!ogicse!news.u.washington.edu!hardy.u.washington.edu!rons
- From: rons@hardy.u.washington.edu (Ronald Schoenberg)
- Newsgroups: comp.lang.c++
- Subject: Re: Overloading [] for 2d+ matrixes
- Message-ID: <1idfu8INNen2@shelley.u.washington.edu>
- Date: 6 Jan 93 02:25:12 GMT
- Article-I.D.: shelley.1idfu8INNen2
- References: <1iarmlINN882@ub.d.umn.edu> <HUGH.93Jan5194117@kahu.cosc.canterbury.ac.nz>
- Organization: University of Washington, Seattle
- Lines: 34
- NNTP-Posting-Host: hardy.u.washington.edu
-
- In article <HUGH.93Jan5194117@kahu.cosc.canterbury.ac.nz> hugh@kahu.cosc.canterbury.ac.nz (Hugh Emberson) writes:
-
- [...elision....]
-
- >
- >2) The not so elegant solution.
- >
- >Don't use [], use () instead.
- >
- > Y& X::operator () (whatever, whatever)
- >
- >and use
- >
- > a(i,j);
- >
- >
- >It should be a bit faster, but its not as pretty. It has the same
- >precedence as [] too.
- >
- >Hugh
- >--
- >Hugh Emberson -- CS Postgrad
- >hugh@cosc.canterbury.ac.nz
-
- Ugliness here is in the eye of beholder. Personally, I think addressing
- a two-dimensional array as a[i][j] is ugly. And more work. Maybe it's
- because I touch-type, but I find a(i,j) a lot easier to type than a[i][j].
-
- Trying to overload operator [] for matrix classes generally seems to
- create more problems than it solves. I've some experience with matrix
- classes and that experience suggests that it is better to stick to
- --
- Ronald Schoenberg fax: 206-727-6521
- University of Washington email: rons@u.washington.edu
-