home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2095 < prev    next >
Encoding:
Text File  |  1992-12-30  |  4.0 KB  |  244 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!porsche.visix.com!robert
  3. From: robert@porsche.visix.com (Robert Mollitor)
  4. Subject: Problem with nested classes
  5. Message-ID: <9212291829.AA00556@corrado.visix.com>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 29 Dec 1992 18:29:30 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 231
  12.  
  13. I have encountered a problem with the g++ compiler.  I have included
  14. three versions (A, B, and C) of the same test program.  I would
  15. prefer to use version A, but would settle for version B.  However, only
  16. version C works the way I want it to.
  17.  
  18. Is my approach confused or are there compiler bugs lurking about (other
  19. than the self-proclaimed one)?
  20.  
  21. Thanks,
  22. Robert Mollitor (robert@visix.com)
  23.  
  24. -----------
  25.  
  26. gcc version 2.3.2
  27. SunOS 4.1
  28.  
  29. g++ -o xxx xxx.c
  30.  
  31. A (during compile):
  32. > xxx.c:39: Internal compiler error.
  33. > xxx.c:39: Please report this to `bug-g++@prep.ai.mit.edu'.
  34.  
  35. B (during run):
  36. > foo5
  37. > foo5
  38.  
  39. C (during run):
  40. > foo5
  41. > foo3 bar9
  42.  
  43.  
  44.  
  45. /* A **********************************************************/
  46. extern "C"
  47. {
  48. #include <stdio.h>
  49.  
  50. void printf(const char *, ...);
  51. }
  52.  
  53. class object
  54. {
  55. public:
  56.  
  57.   object() { foo = 5; }
  58.  
  59.   virtual void Print() { printf("foo%d\n", foo); }
  60.  
  61.   class Manager
  62.     {
  63.     public:
  64.       virtual object *CreateObject() { return new object; }
  65.     };
  66.  
  67.   int foo;
  68.  
  69. };
  70.  
  71.  
  72. class subobject : public object
  73. {
  74. public:
  75.  
  76.   subobject() { foo = 3; bar = 9; }
  77.  
  78.   void Print() { printf("foo%d bar%d\n", foo, bar); }
  79.  
  80.   class Manager : object::Manager
  81.     {
  82.     public:
  83.       object *CreateObject() { return new subobject; }
  84.     };
  85.  
  86.   int bar;
  87.  
  88. };
  89.  
  90.  
  91. main(int argc, char **argv)
  92. {
  93.   object::Manager objectManager;
  94.   subobject::Manager subobjectManager;
  95.   object *object1, *object2;
  96.  
  97.   object1 = objectManager.CreateObject();
  98.   object2 = subobjectManager.CreateObject();
  99.  
  100.  
  101.   object1->Print();
  102.   object2->Print();
  103.  
  104. }
  105. /***********************************************************/
  106.  
  107.  
  108.  
  109. /* B **********************************************************/
  110. extern "C"
  111. {
  112. #include <stdio.h>
  113.  
  114. void printf(const char *, ...);
  115. }
  116.  
  117. class object
  118. {
  119. public:
  120.  
  121.   object() { foo = 5; }
  122.  
  123.   virtual void Print() { printf("foo%d\n", foo); }
  124.  
  125.   class Manager
  126.     {
  127.     public:
  128.       virtual object *CreateObject() { return new object; }
  129.     };
  130.  
  131.   int foo;
  132.  
  133. };
  134.  
  135.  
  136. class subobject : public object
  137. {
  138. public:
  139.  
  140.   subobject() { foo = 3; bar = 9; }
  141.  
  142.   void Print() { printf("foo%d bar%d\n", foo, bar); }
  143.  
  144.   class xManager : object::Manager            /*** changed ***/
  145.     {
  146.     public:
  147.       object *CreateObject() { return new subobject; }
  148.     };
  149.  
  150.   typedef xManager Manager;                /*** added ***/
  151.  
  152.   int bar;
  153.  
  154. };
  155.  
  156.  
  157. main(int argc, char **argv)
  158. {
  159.   object::Manager objectManager;
  160.   subobject::Manager subobjectManager;
  161.   object *object1, *object2;
  162.  
  163.   object1 = objectManager.CreateObject();
  164.   object2 = subobjectManager.CreateObject();
  165.  
  166.  
  167.   object1->Print();
  168.   object2->Print();
  169.  
  170. }
  171. /***********************************************************/
  172.  
  173.  
  174.  
  175. /* C **********************************************************/
  176. extern "C"
  177. {
  178. #include <stdio.h>
  179.  
  180. void printf(const char *, ...);
  181. }
  182.  
  183. class object
  184. {
  185. public:
  186.  
  187.   object() { foo = 5; }
  188.  
  189.   virtual void Print() { printf("foo%d\n", foo); }
  190.  
  191.   class Manager
  192.     {
  193.     public:
  194.       virtual object *CreateObject() { return new object; }
  195.     };
  196.  
  197.   int foo;
  198.  
  199. };
  200.  
  201.  
  202. class subobject : public object
  203. {
  204. public:
  205.  
  206.   subobject() { foo = 3; bar = 9; }
  207.  
  208.   void Print() { printf("foo%d bar%d\n", foo, bar); }
  209.  
  210.   class xManager : object::Manager
  211.     {
  212.     public:
  213.       object *CreateObject() { return new subobject; }
  214.     };
  215.  
  216.   typedef xManager Manager;
  217.  
  218.   int bar;
  219.  
  220. };
  221.  
  222.  
  223. main(int argc, char **argv)
  224. {
  225.   object::Manager objectManager;
  226.   subobject::xManager subobjectManager;        /*** changed ***/
  227.   object *object1, *object2;
  228.  
  229.   object1 = objectManager.CreateObject();
  230.   object2 = subobjectManager.CreateObject();
  231.  
  232.  
  233.   object1->Print();
  234.   object2->Print();
  235.  
  236. }
  237. /***********************************************************/
  238.  
  239.  
  240. --
  241. Robert Mollitor                              robert@visix.com
  242. Visix Software Inc.                    ...!uupsi!visix!robert
  243.  
  244.