I have an assignment that requires me to overload the * operator to find the product of two objects of the same class type. The class has two int member member variables, x and y. The product of the two classes should be calculated as (first X * second X) + (first Y * second Y). I have overloaded the * operator within the class based on examples I've seen, but I'm getting the following compiler error:
lab4.cpp:26: no matching function for call to 'Vector2D::Vector2D (int)'
I am not sure what this means. I will paste my code below, and I would appreciate any suggestions.
The culprit: return Vector2D((x * RHS.x) + (y * RHS.y));
Actually, the way you describe the sum:
The product of the two classes should be calculated as (first X * second X) + (first Y * second Y)
that is an integer value. If that's so, then your operator* should return an int, not a const Vector2D, then return (x * RHS.x) + (y * RHS.y); instead.