Use an explicit operator bool for Vector2D

This commit is contained in:
Thomas Goyne 2015-08-19 18:17:42 -07:00
parent d253388c8e
commit e757618b32
2 changed files with 3 additions and 4 deletions

View file

@ -75,8 +75,8 @@ Vector2D Vector2D::Round(float step) const {
return Vector2D(floorf(x / step + .5f) * step, floorf(y / step + .5f) * step);
}
Vector2D::operator unspecified_bool_type() const {
return *this == Vector2D() ? nullptr : &Vector2D::x;
Vector2D::operator bool() const {
return *this != Vector2D();
}
std::string Vector2D::PStr(char sep) const {

View file

@ -28,7 +28,6 @@
class Vector2D {
float x, y;
typedef float Vector2D::*unspecified_bool_type;
public:
float X() const { return x; }
float Y() const { return y; }
@ -42,7 +41,7 @@ public:
bool operator ==(const Vector2D r) const { return x == r.x && y == r.y; }
bool operator !=(const Vector2D r) const { return x != r.x || y != r.y; }
operator unspecified_bool_type() const;
explicit operator bool() const;
Vector2D operator -() const { return Vector2D(-x, -y); }
Vector2D operator +(const Vector2D r) const { return Vector2D(x + r.x, y + r.y); }