toString() on struct template

Henning Hasemann hhasemann at web.de
Thu Mar 1 10:43:10 PST 2007


O
> And finally compiled it like thus:
> 
>     dmd FooLib.lib main.d
> 
> This would fail since FooLib.lib doesn't actually *have* the
> implementation of Foo in it.  In order for D to compile a templated
> struct or class into a library, it would need to compile it for every
> possible type, which obviously isn't going to happen.

The more I play around with my code the more I think you are right.
But I dont understand why I dont get an error at compile time but at
runtime?
Shouldnt the compiler already see if the template instantiation
is available or not in the linking step?
 
> If you want to use templates in a library, you *need* to ship and
> compile against the source code, not against a precompiled library.  The
> one exception to this is that it should work for any templates you've
> explicitly instantiated. So, if you append this to Foo's source file:
> 
>   alias Foo!(int) FooInt;
> 
> then it should work.

The problem occurs also when the "main module" does not call any template
function but only code from inside the library does.
Can you explain that with your theory?
What would be the solution?

Henning



More information about the Digitalmars-d mailing list