home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!bunyip.cc.uq.oz.au!uqcspe!cs.uq.oz.au!warwick
- From: warwick@cs.uq.oz.au (Warwick Allison)
- Newsgroups: comp.sys.atari.st
- Subject: Re: problems with gcc/g++
- Message-ID: <9494@uqcspe.cs.uq.oz.au>
- Date: 23 Jul 92 00:04:14 GMT
- References: <bnell.711691021@cadillac> <bnell.711729074@ferrari>
- Sender: news@cs.uq.oz.au
- Reply-To: warwick@cs.uq.oz.au
- Lines: 61
-
- > [re templates]
-
-
- Templates DO work (to a certain degree, partially limited by the inexactness
- of the definition of the language).
-
- If you RTFM, you'll see that you CANNOT "compile" a template. That doesn't
- make any sense. A template is a *template* for creating code, not the
- code itself. The usual procedure is to #include the .cc file of the
- "implementation" of the template. When you think about it, it's all pretty
- obvious (what is the compiler SUPPOSED to do with the uninstantiated
- template? - you get just what you get if you have a heap of #define macros
- but no actual usage of the macros - ie. nothing). This:
-
- gcc -c templ.cc
-
- Where templ.cc is all template "implementation", is the same as compiling
- the empty file (except it takes slightly longer, as the compiler reads in
- all this talk about what you're GOING to do, even though you never actally
- do anything).
-
-
- So, try:
-
- #include <Set.cc>
-
- main()
- {
- Set<int> MySetOfIntegers;
- ...
- }
-
-
- Personally, I would prefer people to use the ".t" extension for the
- implementations of templates, but how would I ever get that?
-
-
- Also, by now you've probably realized "Hey, but I'll get copies of the
- same code in every module that imports Set.cc", which will then clash
- at link time. Correct. The solution to this is beyond the scope of
- the language however - it is an environmental concern of how to only
- create one copy of an instantiation of a template. How can the
- compiler know what other modules.o you have written that have used
- whatever templates? The general solution, is to only #include the .h of
- the template (the definition) in every module of the project you are
- working on, then writing a single module that instantiates all the
- classes and templates you need. How you do this may range from simply
- seeing what link-time errors you get, through manual or automatic
- source-based analysis of what instantiations of a template you make,
- all the way to a more powerful linker that can generate, as an option,
- the module that instantiate all the missing implementations (this, I
- believe, is the correct solution, but whose to write it...).
-
- --
- Warwick
-
- --
- _-_|\ warwick@cs.uq.oz.au /Disclaimer:
- / * <-- Computer Science Department, /
- \_.-._/ University of Queensland, / void (if removed)
- v Brisbane, Australia. /
-