Mail Archives: djgpp/2001/01/22/07:22:22
In comp.os.msdos.djgpp Rafal Maj <maj_rafal AT poczta DOT onet DOT pl> wrote:
> By the way... why is it realy so incredibly hard to implement ?
Because it breaks in a fundamental way how a compiler works together
with the linker.
A template isn't really source code: it's just a recipe for making
code, in a way, with the details depending on the particular type you
instantiate the template with. The fundamental problem is: _when_ is
this code going to be compiled?
You can't usually compile the implementation source file on its own,
because you don't know which types the template will be inst'ed with,
elsewhere. But at the place where the code *is* used, your approach
with a separate implementation file tries to hide the implementation,
so it can't be compiled there, either.
So both .o files reach the linker, but the template never was compiled
for the particular type you used it with ---> the linker sees this and
barfs.
The '-frepo' flag of GCC tries to get around another, related aspect
of templates, by causing compilation steered by the linker. I.e. as
the linker sees that templated code is not compiled in any of the
modules linked in, it asks the compiler to compile those templates,
and then redoes the linking, until all the missing template
implementations are resolved.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -