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

  1. Path: sparky!uunet!destroyer!fmsrl7!ef2007!pt0204.pto.ford.com!fox
  2. From: fox@pt0204.pto.ford.com (Ken Fox)
  3. Newsgroups: comp.lang.c++
  4. Subject: typedefs in the scope of a class
  5. Date: 16 Nov 1992 23:03:11 GMT
  6. Organization: Power Train Systems, Ford Motor Company
  7. Lines: 70
  8. Distribution: world
  9. Message-ID: <1e99bfINN3l2@ef2007.efhd.ford.com>
  10. Reply-To: fox@pt0204.pto.ford.com
  11. NNTP-Posting-Host: pt0204.pto.ford.com
  12. Keywords: typedef, scope, name space
  13.  
  14. I've come across strange behavior (at least to me...) in the interpretation
  15. of "nested" classes.  I want classes stored in files according to functional
  16. classification, but also I want to place them into a "package," or name
  17. space that I can control.  I thought that I could just create bizzare class
  18. names and then use typedefs to put them into the scope of a class which would
  19. serve as my name space... but I'm obviously missing something here because
  20. this "simple" example won't work.
  21.  
  22. Could somebody please explain this?
  23.  
  24. // ======================================================================
  25. // BAD CODE - Why is this broken?
  26. // ======================================================================
  27.  
  28. class myint
  29. {
  30.     public:
  31.     int value;
  32. };
  33.  
  34. class scope
  35. {
  36.     public:
  37.     typedef int SystemInt;
  38.     typedef myint CustomInt;
  39. };
  40.  
  41. int main()
  42. {
  43.     scope::SystemInt i;
  44.  
  45.     // syntax error on next declaration!
  46.  
  47.     // cfront 2.1: CustomInt is not a type name
  48.     // gcc 2.3: `CustomInt' is not a member of type `scope'
  49.  
  50.     scope::CustomInt j;
  51. }
  52.  
  53. // ======================================================================
  54. // GOOD CODE - Why this and not that?
  55. // ======================================================================
  56.  
  57. class scope
  58. {
  59.     public:
  60.     typedef int SystemInt;
  61.     class CustomInt
  62.     {
  63.         public:
  64.         int value;
  65.     };
  66. };
  67.  
  68. int main()
  69. {
  70.     scope::SystemInt i;
  71.     scope::CustomInt j;
  72. }
  73.  
  74. Thanks in advance...
  75.  
  76. -- 
  77.  
  78. Ken Fox (fox@pt0204.pto.ford.com)  | My opinions or statements do not
  79.                                    | represent those of, nor are endorsed by,
  80.                                    | Ford Motor Company.
  81. CAD/CAM Technology Section         |
  82. CAD/CAM/CAE Process Integration    | "Is this some sort of trick question
  83. Ford Motor Company                 |  or what?" -- Calvin
  84.