home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18735 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  1.5 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-cv!ogicse!news.u.washington.edu!hardy.u.washington.edu!rons
  2. From: rons@hardy.u.washington.edu (Ronald Schoenberg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Overloading [] for 2d+ matrixes
  5. Message-ID: <1idfu8INNen2@shelley.u.washington.edu>
  6. Date: 6 Jan 93 02:25:12 GMT
  7. Article-I.D.: shelley.1idfu8INNen2
  8. References: <1iarmlINN882@ub.d.umn.edu> <HUGH.93Jan5194117@kahu.cosc.canterbury.ac.nz>
  9. Organization: University of Washington, Seattle
  10. Lines: 34
  11. NNTP-Posting-Host: hardy.u.washington.edu
  12.  
  13. In article <HUGH.93Jan5194117@kahu.cosc.canterbury.ac.nz> hugh@kahu.cosc.canterbury.ac.nz (Hugh Emberson) writes:
  14.  
  15. [...elision....]
  16.  
  17. >
  18. >2) The not so elegant solution.
  19. >
  20. >Don't use [], use () instead.
  21. >
  22. >    Y& X::operator () (whatever, whatever)
  23. >
  24. >and use
  25. >
  26. >    a(i,j);
  27. >
  28. >
  29. >It should be a bit faster, but its not as pretty.  It has the same
  30. >precedence as [] too.
  31. >
  32. >Hugh
  33. >--
  34. >Hugh Emberson -- CS Postgrad
  35. >hugh@cosc.canterbury.ac.nz
  36.  
  37. Ugliness here is in the eye of beholder.  Personally, I think addressing
  38. a two-dimensional array as a[i][j] is ugly.  And more work.  Maybe it's
  39. because I touch-type, but I find a(i,j) a lot easier to type than a[i][j].
  40.  
  41. Trying to overload operator [] for matrix classes generally seems to 
  42. create more problems than it solves.  I've some experience with matrix
  43. classes and that experience suggests that it is better to stick to 
  44. -- 
  45. Ronald Schoenberg                    fax: 206-727-6521
  46. University of Washington           email: rons@u.washington.edu
  47.