home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / g / bug / 1853 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.5 KB  |  124 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!algorithmics.COM!jody
  3. From: jody@algorithmics.COM (Jody Goldberg)
  4. Subject: Inheritance bug
  5. Message-ID: <9211200051.AA20878@lira>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: Gnus Not Usenet
  8. Distribution: gnu
  9. Date: Thu, 19 Nov 1992 14:51:00 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 111
  12.  
  13. Using gcc-2.3.1 on a Sparc II running 4.1.3 with libg++-2.2 the following code
  14. produces.
  15. ---------------------------------------------
  16. g++ -v
  17. Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/specs
  18. gcc version 2.3.1
  19. ---------------------------------------------
  20. g++ Test.C ; ./a.out
  21. ----------
  22. 3
  23. 3
  24. ---------------------------------------------
  25. We expected
  26. -----------
  27. 1
  28. 2
  29. ------------------------
  30. Test.H
  31. ------
  32. #include <iostream.h>
  33.  
  34. class A
  35. {
  36. public:
  37.     virtual ~A();
  38.     virtual int type(void);
  39. };
  40.  
  41. class B
  42. {
  43. public:
  44.     virtual ~B();
  45. };
  46.  
  47.  
  48. class C0 : public B, public A
  49. {
  50. public:
  51.     int type(void);
  52. };
  53.  
  54. class C1 : public C0
  55. {
  56. public:
  57.     int type(void);
  58. };
  59.  
  60. class C2 : public C0
  61. {
  62. public:
  63.     int type(void);
  64. };
  65.  
  66. class C3 : public C0
  67. {
  68. public:
  69.     int type(void);
  70. };
  71. ----------------------------
  72. Test.C
  73. ------
  74.  
  75. #include "Test.H"
  76.  
  77. A::~A()
  78. {
  79. }
  80.  
  81. int A::type(void)
  82. {
  83.     return 1;
  84. }
  85.  
  86. B::~B()
  87. {
  88. }
  89.  
  90. int C0::type(void)
  91. {
  92.     return 0;
  93. }
  94.  
  95. int C1::type(void)
  96. {
  97.     return 1;
  98. }
  99.  
  100. int C2::type(void)
  101. {
  102.     return 2;
  103. }
  104.  
  105. int C3::type(void)
  106. {
  107.     return 3;
  108. }
  109.  
  110. main()
  111. {
  112.     C1* one = new C1;
  113.     C2* two = new C2;
  114.     
  115.     cerr << one->type() << '\n';
  116.     cerr << two->type() << '\n';
  117. }
  118.  
  119.     Thanks
  120.         jody Goldberg
  121.  
  122. jody@algorithmics.com
  123.  
  124.