Mixin virtual functions -- overloads
Justin
mrjnewt at gmail.com
Mon Feb 23 15:09:54 PST 2009
I'm having some trouble getting mixed-in functions to override each other properly. Here's the function I've templated:
private template tRegister(T) {
static public BindableProperty Register(string propName, TypeInfo ti, BindableObject owner, T defaultValue) {
return _Register(propName, ti, owner, (cast(void*)defaultValue));
}
}
Then, in a class, I'm mixing it in numerous times:
mixin tRegister!(bool) tm_bool;
mixin tRegister!(byte) tm_byte;
mixin tRegister!(ubyte) tm_ubyte;
mixin tRegister!(int) tm_int;
mixin tRegister!(uint) tm_uint;
mixin tRegister!(long) tm_long;
mixin tRegister!(ulong) tm_ulong;
mixin tRegister!(float) tm_float;
mixin tRegister!(double) tm_double;
mixin tRegister!(real) tm_real;
mixin tRegister!(char) tm_char;
mixin tRegister!(char[]) tm_string;
mixin tRegister!(Object) tm_Object;
I then have a bunch of aliases like so:
alias tm_bool.Register Register;
alias tm_byte.Register Register;
alias tm_ubyte.Register Register;
...etc.
In a unittest, I try making these calls:
NameProperty = BindableProperty.Register("Name", typeid(string), this, "Donald");
AngerProperty = BindableProperty.Register("Anger", typeid(uint), this, cast(uint)(0));
Compilation breaks at the second line with these errors:
A.d(122): function alias A.BindableProperty.Register called with argument types:
(char[5u],TypeInfo,Duck,uint)
matches both:
A.BindableProperty.tRegister!(bool).Register(char[],TypeInfo,BindableObject,bool)
and:
A.BindableProperty.tRegister!(char).Register(char[],TypeInfo,BindableObject,char)
It shouldn't match either of these, only the uint overload.
More information about the Digitalmars-d
mailing list