// esercizio 3: Point2D
class Point2D {
private:
float x, y; // coordinate
public:
// methods
float get_x() { return x; };
float get_y() { return y; };
// operators overloading
const Point2D operator=(const Point2D ©) {
if(© == this)
return *this;
x = copy.x;
y = copy.y;
return *this;
}
const Point2D operator++(int) {
x++;
y++;
return *this;
}
const Point2D operator++() {
x++;
y++;
return *this;
}
const Point2D operator--() {
x--;
y--;
return *this;
}
const Point2D operator--(int) {
x--;
y--;
return *this;
}
const Point2D operator+(const Point2D &op) {
Point2D r(*this);
r.x += op.x;
r.y += op.y;
return r;
}
const Point2D operator-(const Point2D &op) {
Point2D r(*this);
r.x -= op.x;
r.y -= op.y;
return r;
}
// ctors
Point2D()
: x(0), y(0)
{ }
Point2D(float nx, float ny)
: x(nx), y(ny)
{ }
Point2D(const Point2D ©)
: x(copy.x), y(copy.y)
{ }
};