stuck on opDiv / opBinary
BBasile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 30 11:12:38 PDT 2015
On Sunday, 30 August 2015 at 17:02:58 UTC, Spacen Jasset wrote:
> I have just added an opDiv to this class, but it doesn't seem
> to pick it up.
> math/vector.d(30): Error: 'this /= mag' is not a scalar, it is
> a Vector3
>
> I can't see why that is, becuase my opMul works in the same
> place. Can anyone point out what I have done wrong?
>
> Class Matrix {
>
> void normalise()
> {
> const float mag = magnitude();
> if (mag) {
> //this.scalarDivide(mag);
> this /= mag; // Not work
> this *= 1/mag; // Does work.
>
> }
> }
>
> // Vector3 opBinary(string op)(Vector3 rhs) if (op=='/')
> Vector3 opDiv(float scalar)
> {
> Vector3 v = this;
> v.scalarDivide(scalar);
> return v;
> }
>
> }
try
---
Vector3 opBinary(string op)(Vector3 rhs)
{
static if (op =="/"){}
else static assert(0, op ~ " not implemented");
}
---
you used the char litteral delims ('') instead of the strings
ones ("").
More information about the Digitalmars-d-learn
mailing list