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

Implement Coord.h

parent e428a172
No related branches found
No related tags found
No related merge requests found
#include "include/coord.h"
#include <string>
Coord::Coord(int x, int y)
: x(x)
, y(y)
{}
int& Coord::operator[](int dimension) {
switch (dimension) {
case 0:
return this->x;
case 1:
return this->y;
}
throw "bad dimension " + std::to_string(dimension);
return this->x;
}
Coord Coord::operator+(const Coord& other) {
return Coord(this->x + other.x, this->y + other.y);
}
Coord Coord::operator-(const Coord& other) {
return Coord(this->x - other.x, this->y - other.y);
}
......@@ -4,9 +4,10 @@
class Coord {
public:
Coord(int, int);
int& operator[](int);
Coord operator+(Coord);
Coord operator-(Coord);
Coord operator+(const Coord&);
Coord operator-(const Coord&);
private:
int x;
......
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