OK, so how does GCC's C++ compiler allow one to compile a templated class's methods in a separate file (other than the header)?
According to Stroustup's The C++ Programming Language, you can specify a "separate compilation strategy" (which he goes on to detail...it's the standard declarations in the header, definitions in the source file strategy known to everyone except dyed-in-the-wool Java programmers). Then he states:
Note that to be accessible from other compilation units, a template definition must be explicitly declared export (\ufffd9.2.3). This can be done by adding export to the definition or to a preceding declaration. Otherwise the definition must be in scope wherever the template is used
OK, kewl! So I place the methods of the templated class in a .cxx file (.cxx is our local choice for the extension of C++ source files), and feed it to GCC. GCC is not pleased; it squaks something about the keyword (and it recognizes it as a keyword, at least) export is not implemented, and will be ignored. Which is then followed by a large amount of noise about not finding the methods in the .cxx file, multiplied by all the templated instances.
OK, so this means that templated classes must be fully implemented in the .h files, right? Well, not quite. You see there is this thing called the STL (among other things, especially by Todd). Given this, the STL should be fully and completely implemented in its headers (after all, the STL for a given version of GCC is compiled in that version of GCC.) Yet, poking around in the STL headers shows that some templated methods of the STL classes are indeed implemented in separate compilation units. But how? I don't have the source to figure this out. So does anybody out there know GCC's magic incantation that, when translated into ANSI C++, becomes export?
(BTW, this is a GCC 3.3.4 compiler, so we're talking about a version that is relatively recent.)
thanx-