interface IMathable
{
public static IMathable operator +(IMathable l, IMathable r);
public static IMathable operator -(IMathable l, IMathable r);
}
Is such possible? I have range of mathmatical class. Vector2/3/4/5/6 Matrix3x3/4x4/5x5/6x6 and so on.
They don't have a common class that they drive from. But they all have operators such as + - * /
I want to have a class like.
class MyClass <T> where T : IMathable
{
T magnitude_required_to_reach_toHere;
public MyClass (IMathable from, IMathable toHere)
{
magnitude_required_to_reach_toHere = from + toHere;
}
}
Is there a way to achieve this? I was advised to have all my math classes to drive from abstract class but I can't have abstract class for all these mathmatical classes since they are built in, part of library; I can't fix the code.