home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15858 < prev    next >
Encoding:
Text File  |  1992-11-07  |  1.9 KB  |  55 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!uwm.edu!caen!saimiri.primate.wisc.edu!ames!sun-barr!sh.wide!fgw!fdm!flab!zodiac!zodiac!vander
  2. From: vander@flab.fujitsu.co.jp (Mike van der Velden)
  3. Newsgroups: comp.lang.c++
  4. Subject: Invoking template base ctor
  5. Message-ID: <VANDER.92Nov6115633@vancouver.stars.flab.Fujitsu.co.jp>
  6. Date: 6 Nov 92 02:56:33 GMT
  7. Sender: news@zodiac.hi.flab.fujitsu.co.jp
  8. Organization: Fujitsu Laboratories Ltd., Kawasaki, Japan
  9. Lines: 43
  10. Nntp-Posting-Host: vancouver.hi.flab.fujitsu.co.jp
  11.  
  12.  
  13. I'm using g++ (2.2.2?) on a Sun Sparc S-4/1X.  I have the following
  14. code segment.
  15.  
  16.     template <class T>
  17.     class B {
  18.     public:
  19.         B () { /*  */ }
  20.     };
  21.  
  22.  
  23.     class D : public B<D> {
  24.     public:
  25.         D() : () {}     // compiles fine
  26.         D() : B() {}    // error:  class `D' does not have any field named `B'
  27.     };
  28.  
  29.  
  30. I always used the second method of invoking the base class
  31. constructor, but the compiler complained about it.  I was at wits end
  32. until I noticed that the ARM uses the first method in one of its
  33. examples in the section about templates (sorry, I left the book at
  34. home this morning, so I don't know the exact page number).  This
  35. works, even though the ARM also states that the first method is the
  36. "old" way of calling a base class constructor.
  37.  
  38. Note that if class B is a regular class, and not a template, then
  39. either method of invoking the base class constructor works.
  40.  
  41. Is this correct behaviour (ie. since the ARM does it...) or a known
  42. deficiency in the g++ compiler?  How can I achieve multiple
  43. inheritance in this case?
  44.  
  45. Our AT&T compiler (version 2.1) doesn't even handle templates, so
  46. switching compilers at this point is not really an option...
  47.  
  48. --
  49.  
  50. -- 
  51. Mike van der Velden             
  52. s-mail: Distributed Systems Laboratory, Fujitsu Laboratories Ltd.
  53.         1015, Kamikodanaka Nakahara-ku, Kawasaki 211, Japan
  54. e-mail: vander@flab.fujitsu.co.jp
  55.