home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13549 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.3 KB  |  51 lines

  1. Path: sparky!uunet!snorkelwacker.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: zero-length datatype
  5. Message-ID: <TMB.92Sep11212337@arolla.idiap.ch>
  6. Date: 12 Sep 92 01:23:37 GMT
  7. References: <TMB.92Sep8141523@arolla.idiap.ch> <4947@holden.lulea.trab.se>
  8.     <HAYDENS.92Sep9215705@bullwinkle.juliet.ll.mit.edu>
  9.     <TMB.92Sep10120206@arolla.idiap.ch>
  10.     <HAYDENS.92Sep10103208@bullwinkle.juliet.ll.mit.edu>
  11. Sender: news@ai.mit.edu
  12. Reply-To: tmb@idiap.ch
  13. Distribution: comp
  14. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  15.     Perceptive)
  16. Lines: 32
  17. In-reply-to: haydens@bullwinkle.juliet.ll.mit.edu's message of 10 Sep 92 17:32:08 GMT
  18.  
  19. In article <HAYDENS.92Sep10103208@bullwinkle.juliet.ll.mit.edu> haydens@bullwinkle.juliet.ll.mit.edu (Hayden Schultz x3685 g42) writes:
  20.  
  21.    I'm still not convinced that you can't use existing language features
  22.    to solve (or maybe just avoid) this problem. If a legitimate subset of
  23.    the hash table problem is hash tables with just keys, then this sounds
  24.    like a basis for a class heirarchy. [... example deleted ...]
  25.  
  26.    I think that this meets your intuitive criterion. Whenever you don't
  27.    care what the values are, you use the KeyHash class. You don't have to
  28.    make a special class to make a simple HashTable<int,int>. The Key and
  29.    Value types are as explicit as your original example. You don't even
  30.    have to modify any existing code which uses the HashTable class, since
  31.    the public interface hasn't changed.
  32.  
  33. The number of classes you need might be large. Consider the following:
  34.  
  35.     template <class A,class B,class C>
  36.     class XYZ { ... }
  37.  
  38. Now, you already need 7 different versions of XYZ, depending on which
  39. of "A", "B", "C" are "void" (assuming not all of them are "void"
  40. simultaneously), and it is not clear that every such class can be
  41. decomposed neatly into a class hierarchy, even with multiple
  42. inheritance.
  43.  
  44. So, sure, you can reorganize your code and introduce several classes
  45. (there are other, less object-oriented and more general approaches as
  46. well). However, why bother? "void" can be a perfectly good data type,
  47. and it has proven its utility in other languages. It's no big deal, it
  48. is simply that the restrictions on it in C++ seem arbitrary.
  49.  
  50.                     Thomas.
  51.