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

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