There are a couple of issues here. Separate compilation has been addressed much better than I could do. However, there is a simple issue that is being overlooked. Maybe it only matters to a few of us, anyway.
It is _not_ , repeat, _not_ necessary to include definition code in the header. If you like to separate the declarations and defintions for the purpose of code organization, then it is still possible to do so. I can't speak for all compilers, but I can speak for MS visual C (and if MS can do it then anybody can). But it is important to remember that this is just for code organization. The difference comes when you want to use the template class in other code. Instead of including the header simply include the source code. This doesn't get around the separate compilations, but only addresses code organization.
Just as a side note, Silicon Graphics compiler for unix a couple years ago did an excellent job of using only the header code for the includes. The compiler was incremental. As it identified additional files that were needed in order to instantiate a template class function, it would go find the necessary file and include it. If additional files were identified in the process, it would chase them down. I am not sure about the current status of their compiler--it has been a couple of years since I used it heavily for template programming.
Dave Rich
>>> mito@masa.ims.ac.jp 04/16/01 12:35AM >>>
Thank you all for replying to my question and writing about "export"
keyword. I'm not sure I can completely understand this template
instantiation issue and "export", but this keyword does not seem to
enable to do separate compilation.
I've realized that C++ templates require more intelligence from the
programming environment than one finds on a usual system. Somehow the
compiler and linker have to make sure that each template instance
occurs exactly once in the executable. But it is so difficult that
one sometimes has trouble in using automatic instantiation which
seriously depends on the compiler.
I think that explicit instantiation is a good idea to make sure
exactly one template instance in the executable. But you cannot know
what kind of expression template object is to be instantiated in the
executable, so that the method cannot deal with expression templates.
After all, I think I'd better continue to put both template
declarations and implementations into header files. ( I wish
I might get a smarter IDE which help me out of this mess. )
Masakatsu Ito
Computer Center of Institute for Molecular Science
E-mail mito@ims.ac.jp
--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org
--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:15 EST