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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!sun-barr!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!uwm.edu!caen!destroyer!gumby!wupost!darwin.sura.net!max.fiu.edu!serss0!feathers
  3. From: feathers@serss0 (Michael Feathers)
  4. Subject: Re: Two things: typeof() and exceptions
  5. Organization: Florida International University, Miami
  6. Date: Mon, 16 Nov 1992 23:34:00 GMT
  7. Message-ID: <Bxu1Gp.M9o@fiu.edu>
  8. References: <MCGRANT.92Nov15134127@rascals.stanford.edu> <1992Nov16.202036.1@vax1.bham.ac.uk>
  9. Sender: news@fiu.edu (Usenet Administrator)
  10. Lines: 45
  11.  
  12. In article <1992Nov16.202036.1@vax1.bham.ac.uk> mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
  13. >
  14. >IMHO we should always think carefully before adding a new token to
  15. >the language after all some poor sod will have used it as a symbol.
  16. >It would not detract from the readability to use class() instead.
  17. >
  18. >There is a presedent for using the token `class' in this way:
  19. >  `template<class T>' "class" meaning "T is a symbol of type class"
  20. >  `class(xxx)' "class" meaning "Convert xxx to a value of type class"
  21. >
  22.  
  23.  
  24. This is a great point of departure for another question: 
  25.  
  26. Why does the syntax for a template require the class keyword when templates
  27. are instantiable to the predefined types of C++ (int, double, etc.,.)?
  28.  
  29. I suspect the reason is to disambiguate expressions and class/type names
  30. as parameters to templates.  However, it is a wonderful start towards 
  31. perhaps making the predefined types of C++ behave as classes.  It would
  32. be nice to be able to inherit from int or float, for instance.  Anyone
  33. who would want to do something like this today needs to make a class
  34. with an int or float member.  Most compilers that I've run into still
  35. generate code which accesses the single member like a struct even though
  36. it is at offset zero in the struct.
  37.  
  38. What would we do for syntax?  How about this:
  39.  
  40. class Integer : public int
  41. {
  42.     public:
  43.         operator int () { return *this; }
  44. };
  45.  
  46. *this would be the access for the int portion of an Integer.  Note that
  47. if there were additional members in class Integer, an int cast would have
  48. the effect of "object-slicing" *this to only the int portion.
  49.  
  50. I'm not sure if such lvalue casting is now allowed.  All of this is off
  51. the top of my head, but I think that making the predefined types into 
  52. classes would certainly help the orthogonality of the language.
  53.  
  54. The syntax of templates certainly suggests that predefined types are
  55. sort of like classes, doesn't it?
  56.  
  57.