Weird link error
CodeSun via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 20 10:02:17 PDT 2015
I have test a snippet of code, and I encountered with a weird
link error.
The following is the demo:
import std.stdio;
interface Ti {
T get(T)(int num);
T get(T)(string str);
}
class Test : Ti {
T get(T)(int num) {
writeln("ok");
}
T get(T)(string str) {
writeln(str);
}
}
void main() {
Ti tt = new Test;
tt.get!string("test");
tt.get!string(123);
}
When I use dmd to compile this code snippet, the following link
error was reported:
tt.d:(.text._Dmain+0x3b):‘_D2tt2Ti12__T3getTAyaZ3getMFAyaZAya’
undefined reference
tt.d:(.text._Dmain+0x49):‘_D2tt2Ti12__T3getTAyaZ3getMFiZAya’undefined
reference
And if I modigy the code to
Test tt = new Test;
then this code will work.
So does it mean I can't declare function template inside
interface? If so, why didn't dmd report the error while compiling
instead of linking?
And where I can find the D symbol definition, because information
like ‘_D2tt2Ti12__T3getTAyaZ3getMFAyaZAya’ makes me really
confused.
More information about the Digitalmars-d-learn
mailing list