home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18541 < prev    next >
Encoding:
Text File  |  1992-12-30  |  2.4 KB  |  60 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!laphroaig!cflatter
  3. From: cflatter@nrao.edu (Chris Flatters)
  4. Subject: Re: template disappointments ... (suggesti
  5. Message-ID: <1992Dec30.165154.25081@nrao.edu>
  6. Sender: news@nrao.edu
  7. Reply-To: cflatter@nrao.edu
  8. Organization: NRAO
  9. References: <MCGRANT.92Dec29191250@gomez.stanford.edu>
  10. Date: Wed, 30 Dec 1992 16:51:54 GMT
  11. Lines: 47
  12.  
  13. In article 92Dec29191250@gomez.stanford.edu, mcgrant@gomez.stanford.edu (Michael C. Grant) writes:
  14. >
  15. >In article <1992Dec29.204431.13413@nrao.edu>
  16. >cflatter@nrao.edu (Chris Flatters) writes:
  17. >   In article 92Dec29133556@muse.cv.nrao.edu,
  18. >   dschieb@muse.cv.nrao.edu (Darrell Schiebel) writes:
  19. >   >    (1) The inability to derive templated classes from a non-templated 
  20. >   >        base class of the same name:
  21. >   >        class typeinfo {};
  22. >   >        template<class t> class typeinfo : public typeinfo {};
  23. >Yeah, that's a bummer. I see no reason why typeinfo and typeinfo<T>
  24. >can't be distinguished by any reasonable compiler.
  25.  
  26. I can.
  27.  
  28. The declaration of a class introduces a new keyword into the language.  After
  29. encountering the declaration "class typeinfo { ... };" the lexical analyser will
  30. recognize "typeinfo" as a class name.  This means that "template<class T>
  31. class typeinfo: public typeinfo {};" looks like:
  32.  
  33. 1) a second definition of typeinfo; and
  34.  
  35. 2) a definition of a class that inherits from itself.
  36.  
  37. In principle it is possible to envision a template name space that is separate
  38. from the class name space but this would require the decision of whether an
  39. identifier is a class name or a template name to be made with some awareness
  40. of the context in which it appears.  This would rule out the use of LR(k)
  41. parsers (such as those generated by yacc) since syntactic elements are not
  42. recognized until all of their components have been scanned.  This is a fairly
  43. hefty price to pay.
  44.  
  45. >
  46. >   This is according to the ARM:
  47. >
  48. >           A class template name must be unique in the program and may not
  49. >           be declared to refer to any other template, class, function,
  50. >           object, value, or type in the same scope.
  51. >                                                           [p343]
  52. >What's yer point? That's why this is called 'template disappointments.'
  53.  
  54. The point is that cfront will reject "template <class T> class foo: public foo {}"
  55. because it is forbidden by the language definition and not because of a compiler
  56. deficiency.
  57.  
  58.     Chris Flatters
  59.     cflatter@nrao.edu
  60.