No subject
Sun Jan 14 16:13:07 PST 2007
-- class A, matches (Object) better than (void*), so just do the Right thing
to choose overloaded-function(Object obj).
====================================
$ cat ts.d
import std.string;
class A{}
struct B{
char[] toString() {return "B";}
}
int c;
char[] toStringFunc(Object obj) {return obj.toString();}
char[] toStringFunc(int i) {return format(i);}
char[] toStringFunc(void* obj) {return "null";}
class S(T) {
T obj;
char[] toString() {
return toStringFunc(obj);
}
}
int main(char[][] args) {
S!(A) sa;
S!(B*) sb;
S!(int) sc;
printf("%.*s", sa.toString());
printf("%.*s", sb.toString());
printf("%.*s", sc.toString());
return 0;
}
$ dmd.exe ts.d
ts.d(19): function ts.toStringFunc called with argument types:
(A)
matches both:
ts.toStringFunc(Object)
and:
ts.toStringFunc(void*)
ts.d(25): template instance ts.S!(A) error instantiating
====================================
Come on! class A matches both (Object) and (void*)?!
--
More information about the Digitalmars-d-bugs
mailing list