home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13720 < prev    next >
Encoding:
Internet Message Format  |  1992-09-15  |  2.6 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Proposal: Subscripting with multiple arguments
  5. Message-ID: <TMB.92Sep16020514@arolla.idiap.ch>
  6. Date: 16 Sep 92 06:05:14 GMT
  7. Article-I.D.: arolla.TMB.92Sep16020514
  8. References: <1992Sep14.182942.1986@athena.mit.edu>
  9.     <MATT.92Sep14161955@physics.berkeley.edu>
  10.     <TMB.92Sep15134433@arolla.idiap.ch> <jac.716576376@moonshine>
  11. Sender: news@ai.mit.edu
  12. Reply-To: tmb@idiap.ch
  13. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  14.     Perceptive)
  15. Lines: 36
  16. In-reply-to: jac@moonshine.llnl.gov's message of 15 Sep 92 16:59:36 GMT
  17.  
  18. In article <jac.716576376@moonshine> jac@moonshine.llnl.gov (James A. Crotinger) writes:
  19.  
  20.    tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  21.    > What you can do, however, is to share a lot of code among the
  22.    > different array classes. For example, you might have your
  23.    > multidimensional array inherit from your 1D array.
  24.  
  25.      Not publicly, I hope. There is no "is a" relationship in that
  26.    direction. (Well, you can say that a 2D array of floats is a 1D array
  27.    of 1D arrays of floats, but that's not the same as inheritance since
  28.    the types of the 2D and "outer" 1D arrays are different.)  In one of
  29.    our class libraries we did implement "Vector" (1D array) as inheriting
  30.    from "Matrix" (2D array). This makes sense since a Vector is just a
  31.    Matrix with only 1 column. Thus you can safely pass a Vector to any
  32.    function which operates on Matrices, etc. You would not want to try to
  33.    do the reverse.
  34.  
  35. Actually, an n-dimensional array "is a" concatenation of n-1
  36. dimensional arrays, quite naturally, so public inheritance does make
  37. sense. For reasons of efficiency, it may still be better to have a
  38. specialized class unrelated to all the others for each dimensionality.
  39.  
  40. The case of vectors and matrices is very different from the case of
  41. arrays, since there is a lot of additional structure. In fact, I don't
  42. think there is a single clean way to express the relationship between
  43. vectors and matrices within the OO paradigm, since these relationships
  44. don't form a taxonomy. Sometimes, it makes sense to view a vector as a
  45. one-column (or one-row) matrix, while at other times, it makes sense
  46. to view an N x M matrix as an NM dimensional vector.
  47.  
  48. In such cases where different taxonomies are plausible, it is usually
  49. best not to use any taxonomy and rely on explicity conversion
  50. functions. So, I think Vector should not inherit from Matrix, and
  51. Matrix should not inherit from Vector.
  52.  
  53.                     Thomas.
  54.