Mail Archives: djgpp/1998/09/07/22:46:04
Fabrice ILPONSE wrote:
> > I think it has to do with the way templates are handled. math.o is small
> > because there is (effectively) nothing in it. Templates are only compiled
> > when a reference to them if found. No references are found in math.cc. I
> > don't think the linker will link templated functions that had no instances
> > during compilation.
>
> I'm not sure!!
> You have to put all the class in the header.
> The functions are recreated each time you declare a new template
> variable of an inexisting type.
>
> eg.
> matrix <int> a,b;
> matrix <float> c;
>
> in fact there'll be 2 differents classes: 1 for int and 1 for float.
> So as the compiler need to know the body of the functions to rebuild
> them, they must be in the header file.
And this happens at COMPILE time, not LINK time. If during COMPILE time,
there are no instances, then you can't link a program with instances.
Conclusion: Don't make a template library file. You can't precompile
templates, they must be compiled in the same module as the declarations.
--
(\/) Endlisnis (\/)
s257m AT unb DOT ca
Endlisnis AT GeoCities DOT com
Endlis AT nbnet DOT nb DOT ca
- Raw text -