Here are some snippets of the essential parts of the code.
class mat2{public: /* Constructors and Deconstructors */ // No arguments gives an Identity Matrix mat2() { Identity(1.0f); } mat2(const float c) { Identity(c); } mat2(const float c0, const float c1, const float c2, const float c3) { m[0] = c0; m[1] = c1; m[2] = c2; m[3] = c3; } mat2(const mat2 &n) { *this = n; } ~mat2() {} /* Array operator */ float &operator[] (int i); const float &operator[] (int i) const; const float &operator() (unsigned int i, unsigned int j) const; float &operator() (unsigned int i, unsigned int j); /* Arithmetic operators */ mat2 &operator=(const mat2 &n); mat2 operator*(const mat2 &n); mat2 operator*=(const mat2 &n);protected: // This is arranged in rows format // Each row contains one 2D Vector enum { mat2lim = 4, row2lim = 2, col2lim = 2 }; float m[mat2lim];};
And here's the definitions of the class functions.
inline float &mat2::operator[] (int i) { return m;}inline const float &mat2::operator[] (int i) const { return m;}/* Parenthesis operator */const float &mat2::operator() (unsigned int i, unsigned int j) const { return m[(i * row2lim) + j];}float &mat2::operator() (unsigned int i, unsigned int j) { // Row based matrix index return m[(i * row2lim) + j];}/* Arithmetic operators */inline mat2 &mat2::operator=(const mat2 &n) { for(int i = 0; i < mat2lim; i++) { m = n; } return *this;}inline mat2 mat2::operator*(const mat2 &n) { mat2 r; r.m(0, 0) = m(0, 0) * n.m(0, 0) + m(0, 1) * n.m(1, 0); // r[0][0] r.m(0, 1) = m(0, 0) * n.m(0, 1) + m(0, 1) * n.m(1, 1); // r[0][1] r.m(1, 0) = m(1, 0) * n.m(0, 0) + m(1, 1) * n.m(1, 0), // r[1][0] r.m(1, 1) = m(1, 0) * n.m(0, 1) + m(1, 1) * n.m(1, 1); // r[1][1] return(r);}
The last part mat2::operator* is where the error occurs.
I am unsure what the problem is because there has been only one resource that has given me any clue of the overloading of the operator() for this purpose.
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
Can anyone point me in the right direction on fixing this matter?
Thanks