home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13061 < prev    next >
Encoding:
Text File  |  1992-08-30  |  1.9 KB  |  52 lines

  1. Path: sparky!uunet!zephyr.ens.tek.com!uw-beaver!ubc-cs!destroyer!sol.ctr.columbia.edu!usc!cs.utexas.edu!hellgate.utah.edu!fcom.cc.utah.edu!swillden
  2. From: swillden@news.ccutah.edu (Shawn Willden)
  3. Newsgroups: comp.lang.c++
  4. Subject: BC++ templates broken
  5. Message-ID: <1992Aug29.212548.8071@fcom.cc.utah.edu>
  6. Date: 29 Aug 92 21:25:48 GMT
  7. Sender: news@fcom.cc.utah.edu
  8. Organization: University of Utah Computer Center
  9. Lines: 40
  10. X-Newsreader: Tin 1.1 PL3
  11.  
  12. Hi all,
  13.  
  14.     I have discovered a problem with BC++'s templates.  Given code like
  15. this:
  16.  
  17.     template<class T> class A1;
  18.     template<class T> class A2;
  19.     
  20.     template<class T> class A { A1* a; A2* b; };
  21.     template<class T> class A1 : public A<T> {};
  22.     template<class T> class A2 : public A<T> {};
  23.  
  24.     main() {A1<int> myA1;}
  25.  
  26. the compiler chokes, complaining that it cannot expand A2<int> because A<int>
  27. is not yet defined.  Apparently, the expansion of A1<int> causes the expansion
  28. of A<int> which in turn causes the expansion of A2<int> (due to the declaration
  29. of A's member b) but it *can't* expand A2<int> because A<int> hasn't been
  30. expanded yet.  Unfortunately, I have to do this.  As I see it, these are my
  31. options:
  32.  
  33.     1)    'untemplate' these classes, make them deal with 
  34.         void*'s instead of T*'s and do lots of icky casts.
  35.         I *can* do this because these classes are only used
  36.         internally by another class, which is a template and
  37.         could insure type-safety.
  38.     2)    Make A::a and A::b A*'s and provide lots of forwarding
  39.         functions and do lots of fugly downcasting.
  40.     3)    Make the compiler swallow the above code somehow.
  41.     4)    Redesign the class that uses these three (several
  42.         hundred lines of code, none of it mine and all of 
  43.         it ugly - this option does *not* appeal to me.)
  44.     5)    Get a job as a garbage man so I can just chuck 
  45.         people's trash instead of having to fix it :-)
  46.  
  47. Obviously, option 3 is what I really want.  Any ideas?
  48.     
  49. --
  50. Shawn Willden
  51. swillden@icarus.weber.edu
  52.