Проблема с перегрузкой operator+=
Если убрать (float)t из velociti += accseleration * t; то всьо гуд, но operator*(float) возвращает Vector2f.
Код:
class Vector2f
{
public:
float x,y;
Vector2f &operator+=(Vector2f&);
Vector2f operator*(float);
};
Vector2f &Vector2f::operator+=(Vector2f &v2)
{
x += v2.x;
y += v2.y;
return *this;
}
Vector2f Vector2f::operator*(float v2)
{
Vector2f v3;
v3.x = x * v2;
v3.y = y * v2;
return v3;
}
class Bullet
{
public:
Vector2f position,velociti,accseleration;
void Move(float);
};
void Bullet::Move(float t)
{
velociti += accseleration * t; // error: no match for 'operator+=' in '((Bullet*)this)->Bullet::velociti += ((Bullet*)this)->Bullet::accseleration.Vector2f::operator*(t)'
position += velociti * t;
}
{
public:
float x,y;
Vector2f &operator+=(Vector2f&);
Vector2f operator*(float);
};
Vector2f &Vector2f::operator+=(Vector2f &v2)
{
x += v2.x;
y += v2.y;
return *this;
}
Vector2f Vector2f::operator*(float v2)
{
Vector2f v3;
v3.x = x * v2;
v3.y = y * v2;
return v3;
}
class Bullet
{
public:
Vector2f position,velociti,accseleration;
void Move(float);
};
void Bullet::Move(float t)
{
velociti += accseleration * t; // error: no match for 'operator+=' in '((Bullet*)this)->Bullet::velociti += ((Bullet*)this)->Bullet::accseleration.Vector2f::operator*(t)'
position += velociti * t;
}
Код:
class Vector2f
{
public:
float x,y;
Vector2f &operator+=(const Vector2f&);
Vector2f operator*(float);
};
Vector2f &Vector2f::operator+=(const Vector2f &v2)
{
x += v2.x;
y += v2.y;
return *this;
}
Vector2f Vector2f::operator*(float v2)
{
Vector2f v3;
v3.x = x * v2;
v3.y = y * v2;
return v3;
}
{
public:
float x,y;
Vector2f &operator+=(const Vector2f&);
Vector2f operator*(float);
};
Vector2f &Vector2f::operator+=(const Vector2f &v2)
{
x += v2.x;
y += v2.y;
return *this;
}
Vector2f Vector2f::operator*(float v2)
{
Vector2f v3;
v3.x = x * v2;
v3.y = y * v2;
return v3;
}