no operator matches there operands. Vector + Vector()
In Vector class I wrote operator + and it's working perfectly.
1 2 3 4
|
Vector v1;
Vector v2;
v1+v2;
|
But if I do this
1 2 3 4
|
Vector v1;
Vector v2();
v1+v2
|
An error is shown saying "no operator "+" matches there operands operand types are: le::Vector + le::Vector()"
this is Vector code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
class Vector {
int x_ = 0, y_ = 0;
public:
Vector() = default;
Vector(int x, int y);
Vector(sf::Vector2f vector2f);
Vector(sf::Vector2u vector2u);
Vector operator+(const Vector& parameter) {
Vector temp;
temp.x_ += parameter.x_;
temp.y_ += parameter.y_;
return temp;
}
void setX(int x);
void setY(int y);
void setXY(int x, int y);
int getX();
int getY();
std::vector<int> getXY();
float getAngle();
};
|
Thanks.
Last edited on
Vector v2();
That is a function declaration, remove the parentheses :+)
The compiler sees
Vector v2();
as a
function declaration of a function named v2 that returns a Vector and has no parameters.
You have to either remove the parentheses or replace them with curly brackets.
Topic archived. No new replies allowed.