So I have a generic Matrix class that I created which has the following operator overload:
class Matrix
{
public:
Matrix() {}
Matrix(int i, int j, int k) {}
Matrix operator*(const Matrix &right)
{
}
};
I also have a Matrix2 class that inherits from my Matrix class.
class Matrix2 : public Matrix
{
};
When I try to multiply two Matrix2 objects together I get a compiler error stating:
‘there is no operator found which takes a left hand operand of type Matrix2 (or there is no accessible conversion)’
Why is this and how can I properly implement operator overloads with inheritance?
EDIT:
As pointed out my problem was partially because of the “most vexing parse”. Now my problem, I believe, strictly has to do with the operator overload and inheritance.
I can multiply two Matrix objects just fine, but I cannot multiply two Matrix2 objects together.
Matrix2 i;
Matrix2 m;
Matrix result = m * i;
The error message:
error C2678: binary '*' : no operator found which takes a left-hand operand of type 'Matrix2' (or there is no acceptable conversion).
You are biting the Most Vexing Parse. It is a syntactic error leading to the declaration of functions rather than objects.