Skip to content
Snippets Groups Projects
Commit 58d68d05 authored by Ian Prins's avatar Ian Prins
Browse files

Add new arithmetic operators and a copy func

parent ff2b004d
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,10 @@ Coord::Coord()
, y(0)
{}
Coord Coord::copy() {
return Coord(x, y);
}
int& Coord::operator[](int dimension) {
switch (dimension) {
case 0:
......@@ -29,3 +33,11 @@ Coord Coord::operator+(const Coord& other) {
Coord Coord::operator-(const Coord& other) {
return Coord(this->x - other.x, this->y - other.y);
}
Coord Coord::operator+=(const Coord& other) {
return *this + other;
}
Coord Coord::operator-=(const Coord& other) {
return *this - other;
}
......@@ -9,7 +9,9 @@ class Coord {
int& operator[](int);
Coord operator+(const Coord&);
Coord operator-(const Coord&);
Coord operator+=(const Coord&);
Coord operator-=(const Coord&);
Coord copy();
private:
int x;
int y;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment