Hi

I am trying to overload * for matrix multiplications. For some reason the overload doesn't work for more than two consecutive operations (ie. M*T*V).

where ptr20 etc are elements of a matrix. Any advise please.Code:// Overload * for ob1 matrix_square operator*(const matrix_square &left, const matrix_square &right) { int i; matrix_square temp; for(i = 0; i < Grids; i++){ temp.ptr00[i] = left.ptr00[i]*right.ptr00[i] + left.ptr01[i]*right.ptr10[i] + left.ptr02[i]*right.ptr20[i]; temp.ptr01[i] = left.ptr00[i]*right.ptr01[i] + left.ptr01[i]*right.ptr11[i] + left.ptr02[i]*right.ptr21[i]; temp.ptr02[i] = left.ptr00[i]*right.ptr02[i] + left.ptr01[i]*right.ptr12[i] + left.ptr02[i]*right.ptr22[i]; temp.ptr10[i] = left.ptr10[i]*right.ptr00[i] + left.ptr11[i]*right.ptr10[i] + left.ptr12[i]*right.ptr20[i]; temp.ptr11[i] = left.ptr10[i]*right.ptr01[i] + left.ptr11[i]*right.ptr11[i] + left.ptr12[i]*right.ptr21[i]; temp.ptr12[i] = left.ptr10[i]*right.ptr02[i] + left.ptr11[i]*right.ptr12[i] + left.ptr12[i]*right.ptr22[i]; temp.ptr20[i] = left.ptr20[i]*right.ptr00[i] + left.ptr21[i]*right.ptr10[i] + left.ptr22[i]*right.ptr20[i]; temp.ptr21[i] = left.ptr20[i]*right.ptr01[i] + left.ptr21[i]*right.ptr11[i] + left.ptr22[i]*right.ptr21[i]; temp.ptr22[i] = left.ptr20[i]*right.ptr02[i] + left.ptr21[i]*right.ptr12[i] + left.ptr22[i]*right.ptr22[i]; } temp.zeros(); return temp; }