home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / std / cplus / 1083 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.9 KB  |  50 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!sunic!lth.se!newsuser
  3. From: dag@control.lth.se (Dag Bruck)
  4. Subject: Re: Expanding enumerators in inheriting classes
  5. Message-ID: <1992Aug14.193046.6808@lth.se>
  6. Keywords: inheritance, enumerator
  7. Sender: newsuser@lth.se (LTH network news server)
  8. Organization: Department of Automatic Control, Lund, Sweden
  9. References: <1992Aug10.200814.12809@ntmtv> <1992Aug11.133926.28840@actrix.gen.nz> <1992Aug11.190816.8623@inmet.camb.inmet.com> <1992Aug12.192200.6873@ntmtv>
  10. Date: Fri, 14 Aug 1992 19:30:46 GMT
  11. Lines: 37
  12.  
  13. In <comp.std.c++> hildum@ntmtv.UUCP (Eric Hildum) writes:
  14. >
  15. >... C++ already allows duplicate codes
  16.  
  17. Yes, but the definitions are at least in one place, which makes the
  18. code easier to maintain.  Never mind, I'm sure you are aware of the
  19. potential problems.
  20.  
  21. I have implemented extensible enumerations with templates.  I think
  22. the template sollution offers much of what you would like:
  23.  
  24.     - extensible set of enumerators
  25.     - named enumerator symbols
  26.     - type-safe, in the sense that an enumeration variable
  27.       may only be assigned enumerators of the corresponding
  28.       (possibly extended) enumeration
  29.  
  30. However, there are problems:
  31.  
  32.     - the template version is MUCH less efficient, at least
  33.       with current template implementations
  34.     - these enumerators are not compile-time constants, so
  35.       they cannot be used as case labels, for example
  36.     - compiler must allocate storage for enumerators
  37.     - the scope of the enumerator may not match the scope
  38.       of the enumerated type, so garbage values may float
  39.       around in the system
  40.  
  41. It is possible to add additional logic to handle the last problem
  42. listed above, but it does cost a little in run-time performance.
  43.  
  44. I did this excercise as part of the analysis of operator overloading
  45. of enumerations (a C++ standardization issue).  I can post the actual
  46. code if there is enough interest; it's just two pages of code.
  47.  
  48.  
  49.         -- Dag
  50.