hi, I'm trying to port some parts from ginac (www.ginac.de) to C#. But I encountered this:
class Program {
static void Main(string[] args) {
symbol s = new symbol();
numeric n = new numeric();
ex e = s + n; // "Operator + doesn't work for symbol, numeric"
}
}
class ex {
//this should be already be sufficient:
public static implicit operator ex(basic b) {
return new ex();
}
//but those doesn't work as well:
public static implicit operator ex(numeric b) {
return new ex();
}
public static implicit operator ex(symbol b) {
return new ex();
}
public static ex operator +(ex lh, ex rh) {
return new ex();
}
}
class basic {
}
class symbol : basic {
}
class numeric : basic {
}
The correct order should be: implicitly cast symbol->basic->ex, then numeric->basic->ex and then use the ex operator+(ex,ex) function.
In which order is the lookup for implicit casting functions and operator functions done? Is there any way around this?