Created
March 1, 2017 23:14
-
-
Save towc/00ed828f69b999efa514b8f213446958 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "Coordinate.h" | |
| Coordinate::Coordinate(){ | |
| this->x = 0; | |
| this->y = 0; | |
| } | |
| Coordinate::Coordinate( int x, int y ){ | |
| this->x = x; | |
| this->y = y; | |
| } | |
| Coordinate& Coordinate::operator += ( const Coordinate& b ){ | |
| return *this; | |
| } | |
| Coordinate& Coordinate::operator /= ( const int& b ){ | |
| return *this; | |
| } | |
| inline Coordinate operator + ( Coordinate a, const Coordinate& b ){ | |
| return Coordinate( a.x + b.x, a.y + b.y ); | |
| } | |
| inline Coordinate operator / ( Coordinate a, const int& b ){ | |
| return Coordinate( a.x / b, a.y / b ); | |
| } |
This file contains hidden or 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
| #ifndef Coordinate_H | |
| #define Coordinate_H | |
| struct Coordinate { | |
| Coordinate(); | |
| Coordinate( int x, int y ); | |
| Coordinate& operator += ( const Coordinate& b ); | |
| Coordinate& operator /= ( const int& b ); | |
| int x, y; | |
| }; | |
| inline Coordinate operator + ( Coordinate a, const Coordinate& b ); | |
| inline Coordinate operator / ( Coordinate a, const int& b ); | |
| #endif |
This file contains hidden or 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 <iostream> | |
| #include "Coordinate.h" | |
| int main(){ | |
| Coordinate a( 2, 2 ), b( 3, 4 ); | |
| std::cout << ( a + b ).x << "\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment