home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16692 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.9 KB  |  70 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!psinntp!bony1!richieb
  3. From: richieb@bony1.bony.com (Richard Bielak)
  4. Subject: Re: problems designing lists with templates
  5. Message-ID: <1992Nov19.165602.13420@bony1.bony.com>
  6. Organization: multi-cellular
  7. References: <1992Oct26.225959.566@beaver.cs.washington.edu> <1992Oct28.163105.9062@ucc.su.OZ.AU>
  8. Date: Thu, 19 Nov 92 16:56:02 GMT
  9. Lines: 59
  10.  
  11. In article <1992Oct28.163105.9062@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  12.  
  13. [...]
  14.  
  15. >
  16. >    There are 3 ways I can think of off hand to do this.
  17. >
  18. >    1) Supply operator[] for the list class. This what I do.
  19.  
  20. [...]
  21.  
  22. >
  23. >    2) Do as you suggested.  
  24.  
  25. [...]
  26.  
  27. >    
  28. >    3) Use an iterator.
  29.  
  30. [...]
  31.  
  32. >
  33. >No doubt there are even more solutions. The iterator technique is probably
  34. >the best and hardest. The first technique is easy to work with and code.
  35. >It is not necessarily slow either, by providing a cache it is as fast
  36. >for sequential access as the methods (2) and (3) which are constrained
  37. >to sequential access, whereas (1) gives the appearance of random access.
  38. >
  39. >-- 
  40.  
  41. The fourth way is to use a list with "cursor".  The cursor can be a
  42. separate class, or be part of list. You can set the cursor to point to
  43. the first or last element and then move it around. Code my look
  44. something like this:
  45.  
  46.         curs.set_list (list);
  47.         curs.start;
  48.         curs.forth;
  49.  
  50.         x = curs.item;  // gets the item at the cursor
  51.  
  52.  
  53. The user still doesn't need to see ListElement.
  54.  
  55. This approach is described in more detail in "Object Oriented
  56. Software Construction" by B. Meyer.
  57.  
  58.  
  59.  
  60. ...richie
  61.  
  62.  
  63.  
  64.  
  65. -- 
  66. * Richie Bielak   (212)-815-3072   |                                          *
  67. * Internet:       richieb@bony.com | Rule #1: Don't sweat the small stuff.    *
  68. * Bang {uupsi,uunet}!bony1!richieb | Rule #2: It's all small stuff.           *
  69. *    - Strictly my opinions -      |                                          *
  70.