August 05, 2004 Template instant not created (linker error) | ||||
---|---|---|---|---|
| ||||
The following compiles but does not link: # import std.stdio; # # template Bar(Y) # { # void Bar(Y param) {writefln("The parameter was: ", param);} # } # # template Foo(alias X) # { # alias Bar!(typeof(X)) Foo; # } # # void unused() # { # float f; # // Uncomment this line and the linker error disappears # // Bar!(typeof(f))(f); # } # # void main() # { # float f = 1.2; # # // A really ugly kind of implicit instantiation :-) # mixin Foo!(f); Foo(f); # } Instantiating the template explicitly (even in another scope in an uncalled function) solves the problem. Nick |
Copyright © 1999-2021 by the D Language Foundation