Overloading opEquals(T)(T y)
bearophile
bearophileHUGS at lycos.com
Mon Feb 7 15:16:58 PST 2011
Charles McAnany:
> Hi, all. So I'm trying to make a BigRational struct, to get more comfortable
> with D.
I suggest to ask similar questions in the D.learn newsgroup.
> bool opEquals(Tdummy = void)(BigRational y){
> auto temp = this-y;
> if (temp.numerator == 0)
> return true;
> return false;
> }
>
> bool opEquals(T)(T y){
> return this == BigRational(y);
> }
>
> But this is an ambiguity error.
One possible solution:
bool opEquals(T)(T y) if (is(T == BigRational)) { ... }
bool opEquals(T)(T y) if (!is(T == BigRational)) { ... }
Another solution:
bool opEquals(T)(T y) {
static if (is(T == BigRational)) {
// ...
} else {
// ...
}
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list