Template constraints and opAdd
John
dont at email.me
Mon Jul 1 16:36:26 PDT 2013
I'm getting conflicting templates in this struct and I'm not sure
how. I specifically excluded the second definition of opAdd from
using type T in place of O but the compiler still tells me I'm
getting template conflicts.
Compiler error using Mass!(double,string):
Error: template mass.Mass!(double,string).Mass.opAdd(O) if
((typeof(O)) != (typeof(T))) conflicts with function
mass.Mass!(double,string).Mass.opAdd at src\mass.d(38)
I have a struct:
struct Mass(T, S) {
...
Mass!(T,S) opAdd(Mass!(T,S) other) {
return op!"+"(other);
}
Mass!(O,S) opAdd(O)(Mass!(O,S) other) if (typeof(O) !=
typeof(T)) {
return op!"+"(other);
}
...
}
And I'm trying to do something like:
Mass!(double,string) first = ...
Mass!(double,string) second = ...
auto result = first + second;
I'm trying to add a Mass!(double,string) + Mass!(double,string),
which should mean the second template gets ignored since T=double
and O=double.
What am I missing?
More information about the Digitalmars-d-learn
mailing list