template classes discriminated in receiving invariant arguments
mumba
qniol at o2.pl
Sun Oct 5 17:13:40 PDT 2008
Some strange stuff with templates and invariant-argument method version overload happens. Take a look:
template Template(T, int n) {
class Class {
void foo(T[n] array) {}
void foo(invariant(T[n]) array) {}
}
}
class Class {
void foo(int[3] array) {}
void foo(invariant(int[3]) array) {}
}
int main() {
Template!(int, 3).Class fromTemplate = new Template!(int, 3).Class;
Class normal = new Class;
invariant(int[3]) array = [0, 1, 2];
normal.foo(array); //works fine calling void foo(invariant(int[3])) version
fromTemplate.foo(array); //here is the error
return 0;
}
And the error is following:
template.d(20): function template.Template!(int,3).Class.foo called with argument types:
(invariant(int[3u]))
matches both:
template.Template!(int,3).Class.foo(int[3u])
and:
template.Template!(int,3).Class.foo(int[3u])
Uff, that was crazy message. Let's forget about the fact of omiting invariant keyword by the template... We just created two functions with the same signatures in the same class!
Any ideas?
cheers
More information about the Digitalmars-d-learn
mailing list