home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / atari / st / 11602 < prev    next >
Encoding:
Text File  |  1992-07-22  |  2.7 KB  |  73 lines

  1. Path: sparky!uunet!munnari.oz.au!bunyip.cc.uq.oz.au!uqcspe!cs.uq.oz.au!warwick
  2. From: warwick@cs.uq.oz.au (Warwick Allison)
  3. Newsgroups: comp.sys.atari.st
  4. Subject: Re: problems with gcc/g++
  5. Message-ID: <9494@uqcspe.cs.uq.oz.au>
  6. Date: 23 Jul 92 00:04:14 GMT
  7. References: <bnell.711691021@cadillac> <bnell.711729074@ferrari>
  8. Sender: news@cs.uq.oz.au
  9. Reply-To: warwick@cs.uq.oz.au
  10. Lines: 61
  11.  
  12. > [re templates]
  13.  
  14.  
  15. Templates DO work (to a certain degree, partially limited by the inexactness
  16. of the definition of the language).
  17.  
  18. If you RTFM, you'll see that you CANNOT "compile" a template.  That doesn't
  19. make any sense.  A template is a *template* for creating code, not the
  20. code itself.  The usual procedure is to #include the .cc file of the
  21. "implementation" of the template.  When you think about it, it's all pretty
  22. obvious (what is the compiler SUPPOSED to do with the uninstantiated 
  23. template? - you get just what you get if you have a heap of #define macros
  24. but no actual usage of the macros - ie. nothing).  This:
  25.  
  26.     gcc -c templ.cc
  27.  
  28. Where templ.cc is all template "implementation", is the same as compiling
  29. the empty file (except it takes slightly longer, as the compiler reads in
  30. all this talk about what you're GOING to do, even though you never actally
  31. do anything).
  32.  
  33.  
  34. So, try:
  35.  
  36. #include <Set.cc>
  37.  
  38. main()
  39. {
  40.     Set<int> MySetOfIntegers;
  41.     ...
  42. }
  43.  
  44.  
  45. Personally, I would prefer people to use the ".t" extension for the
  46. implementations of templates, but how would I ever get that?
  47.  
  48.  
  49. Also, by now you've probably realized "Hey, but I'll get copies of the
  50. same code in every module that imports Set.cc", which will then clash
  51. at link time.  Correct.  The solution to this is beyond the scope of
  52. the language however - it is an environmental concern of how to only
  53. create one copy of an instantiation of a template.  How can the
  54. compiler know what other modules.o you have written that have used
  55. whatever templates? The general solution, is to only #include the .h of
  56. the template (the definition) in every module of the project you are
  57. working on, then writing a single module that instantiates all the
  58. classes and templates you need.  How you do this may range from simply
  59. seeing what link-time errors you get, through manual or automatic
  60. source-based analysis of what instantiations of a template you make,
  61. all the way to a more powerful linker that can generate, as an option,
  62. the module that instantiate all the missing implementations (this, I
  63. believe, is the correct solution, but whose to write it...).  
  64.  
  65. --
  66. Warwick
  67.  
  68. --
  69.   _-_|\      warwick@cs.uq.oz.au            /Disclaimer:
  70.  /     * <-- Computer Science Department,  /  
  71.  \_.-._/     University of Queensland,    /      void (if removed)
  72.       v      Brisbane, Australia.        /  
  73.