Hi everyone,

i'm currently working on a small physics engine and I thought it would be a nice feature to overload the operators of my vector struct so I don't have to make ugly function calls just to add and "multiply" my vectors. The problem now is that overloading the addition and subtraction of my vector struct is straight forward because both return and take a vector, dot product is not working for me because it is not possible to overload a function by return type (at least not that I am aware of).

My code looks like the one from the dlang docs:

Vector opBinary(string op)(Vector rhs)
{
static if (op == "+") return Vector(this.x + rhs.x, this.y + rhs.y); else static if (op == "-") return Vector(this.x - rhs.x, this.y - rhs.y);
}

As you can see for the dot product the return type has to be a float/double and not a vector. Is there any way to achive this behaivour with D2? The opMul() function is not D2 style and I don't want to use it.

Thank you very much,

eXodiquas

Reply via email to