I have been trying to get an operator* between two of my classes.
I am building a small geometric library for my game and I have two class templates: Vector<typename T, size_t s>
and Matrix<typename T, size_t rows, size_t columns>
I would like to Multiply the Matrix by a Vector so I have overloaded an operator* in the Matrix class it looks like this.
Vector<T,c> operator*(Vector<T, c>& a)
{
Vector<T,c> t = {{0}};
for(int y=0; y < r; y++)
for(int x = 0;x < c;x++)
t.data[x] += this->data[y*c+x] * a[x];
return t;
}
This works when I place the matrix first and vector second such as Mat_A * Vec_A
but when I reverse them such as Vec_A * Mat_A
the operator* in Vector is called and because the vector class doesn't have a way of determining how many rows has the matrix have I cannot implement the operator.
Is there a way around this without actually reimplementing the whole design?
Thank you