home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13199 < prev    next >
Encoding:
Text File  |  1992-09-02  |  2.2 KB  |  57 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!hellgate.utah.edu!fcom.cc.utah.edu!swillden
  3. From: swillden@news.ccutah.edu (Shawn Willden)
  4. Subject: "Recursive" template problem
  5. Message-ID: <1992Sep2.150611.15090@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah Computer Center
  8. X-Newsreader: Tin 1.1 PL3
  9. References: <1992Aug31.155313.5879@fcom.cc.utah.edu>
  10. Date: Wed, 2 Sep 92 15:06:11 GMT
  11. Lines: 44
  12.  
  13. To any of you who already saw my first post on this subject, I apologize.
  14. However, given the resounding silence that post elicited (no one even
  15. corrected my syntax errors!), I thought maybe I had better try again, 
  16. with a different subject (specifically with one that doesn't include 
  17. 'BC' - since that was in my own kill file for quite some time).
  18.  
  19. The problem is this:  Given a template base class that contains pointers
  20. to two of its derived classes, at least two compilers (gcc-2.2.2 and BC++
  21. 3.1) choke (the former dumps core, the latter reports an error).  The 
  22. code looks something like this:
  23.  
  24. // Forward declarations of A1<T> and A2<T>
  25. template<class T> class A1;
  26. template<class T> class A2;
  27.  
  28. // Now we'll do the actual class definitions.
  29. template<class T> class A {A1<T>* a; A1<T>* b;};
  30. template<class T> class A1 : public A<T> {};
  31. template<class T> class A2 : public A<T> {};
  32.  
  33. int main() {A1<int> myA1;}
  34.  
  35. What happens is, the compiler:
  36.     begins to expand A1<int>, 
  37.     realizes it needs A<int> first,
  38.     begins to expand A<int>,
  39.     *thinks* it needs to expand A2<int> (which it doesn't, because b is
  40.         and A2<int>*),
  41.     begins to expand A2<int>,
  42.     realizes it needs A<int> first,
  43.     notices that A<int> is partially expanded
  44.     and pukes.
  45.  
  46. So, has anyone else seen this problem?  Come up with a work-around?  If I 
  47. get some time I'm going to try to fix gcc but my archie server doesn't
  48. seem to find anything under BC++3.1_source_code.tar.Z ;-) that one's going
  49. to be a little tougher.  Are there any compilers that *do* handle this?
  50. (I only have access to gcc 2.2.2, BC++ 3.1 and some version of Oregon C++
  51. that doesn't support templates [The man page says the -Xv switch tells
  52. Oregon C++ to report what version it is, but it doesn't work]).
  53.  
  54. --
  55. Shawn Willden
  56. swillden@icarus.weber.edu
  57.