Created
December 27, 2012 15:32
-
-
Save castaneai/4389078 to your computer and use it in GitHub Desktop.
二次元座標構造体
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ostream> | |
struct Point | |
{ | |
public: | |
int x; | |
int y; | |
Point operator+(const Point&); | |
Point operator-(const Point&); | |
Point operator*(const int&); | |
Point operator/(const int&); | |
Point& operator+=(const Point&); | |
Point& operator-=(const Point&); | |
Point& operator*=(const int&); | |
Point& operator/=(const int&); | |
friend std::ostream& operator<<(std::ostream&, const Point&); | |
}; | |
Point Point::operator+(const Point& right) | |
{ | |
Point p = {this->x + right.x, this->y + right.y}; | |
return p; | |
} | |
Point Point::operator-(const Point& right) | |
{ | |
Point p = {this->x - right.x, this->y - right.y}; | |
return p; | |
} | |
Point Point::operator*(const int& right) | |
{ | |
Point p = {this->x * right, this->y * right}; | |
return p; | |
} | |
Point Point::operator/(const int& right) | |
{ | |
Point p = {this->x / right, this->y / right}; | |
return p; | |
} | |
Point& Point::operator+=(const Point& right) | |
{ | |
this->x += right.x; | |
this->y += right.y; | |
return *this; | |
} | |
Point& Point::operator-=(const Point& right) | |
{ | |
this->x -= right.x; | |
this->y -= right.y; | |
return *this; | |
} | |
Point& Point::operator*=(const int& right) | |
{ | |
this->x *= right; | |
this->y *= right; | |
return *this; | |
} | |
Point& Point::operator/=(const int& right) | |
{ | |
this->x /= right; | |
this->y /= right; | |
return *this; | |
} | |
std::ostream& operator<<(std::ostream& out, const Point& p) | |
{ | |
out << "(" << p.x << ", " << p.y << ")"; | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment