0

I'm making a matrix3x3 class, and although I have the required functionality thereof the operator overloading as to *=, +=, -= and /= don't work. Here's what I have:

mat3 operator*(const mat3 &m); // Declared within mat3 class

mat3 mat3::operator *=(const mat3& m) // How it's implemented
{
    *this = *this * m;
    return *this;
}

Suffice it to say, that it kinda works; but this is the usage I want:

mat3 m; // Initialise to identity matrix

m *= mat3(2.0); // Multiply matrix by scalar and apply

The problem is that it doesn't affect the matrix at all! m remains the same, even though I've just done a *= mat3(2.0) operation on it. However, this works:

m = m *= mat3(2.0);

Which is just silly, because I might as well do:

m = m * mat3(2.0);

The whole point is that all the above multiplications MUST return the same result. There's no approximations nor compromise here. Quite frankly, all the operators pertaining to *=, += etc do not work. How can I get this kind of operator overload working such that multiplying a matrix and applying that multiplication can be done as easy as:

m *= mat3(2.0)
Poriferous
  • 1,566
  • 4
  • 20
  • 33

0 Answers0