home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15994 < prev    next >
Encoding:
Text File  |  1992-11-09  |  1.3 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!think.com!ames!decwrl!decwrl!world!tob
  3. From: tob@world.std.com (Tom O Breton)
  4. Subject: Re: operator [][]
  5. Message-ID: <BxGtCK.91t@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. References: <BxFt8r.2Kt@cs.columbia.edu> <1992Nov9.095352.19114@fmrco.uucp>
  8. Date: Mon, 9 Nov 1992 20:09:56 GMT
  9. Lines: 42
  10.  
  11.  
  12.  
  13. That is one approach to operator[] for multiple arrays. I have another which:
  14.  
  15.   0:  has the advantage of not requiring intermediate array classes of lesser
  16.       dimensions.
  17.  
  18.   1:  has the disadvantage of requiring another class.
  19.  
  20.   2:  has the property of being suited to multiple arrays that always totally
  21.       de-array(?) themselves, and unsuited to arrays that might deal with
  22.       intermediate sub-arrays.
  23.  
  24. Instead of
  25.  
  26.   operator[](int index)
  27.  
  28. make this class:
  29.  
  30. struct indices  //Struct because it's going to be all open.
  31. { int             index1;
  32.   int             index2;
  33.                   indices(int,int);
  34. };
  35.  
  36. and use it as the argument:
  37.  
  38. class MultArray
  39. { operator[](indices IXs); }
  40.  
  41. You can call it concisely with:
  42.  
  43. //MultArray A;
  44. A[indices(x,y)];
  45.  
  46.         Tom
  47.  
  48.  
  49.  
  50. -- 
  51. The Tom spreads its huge, scaly wings and soars into the wild sky...      
  52. up...       up...     out of sight...   (tob@world.std.com)
  53.