Skip to content

Instantly share code, notes, and snippets.

@towc
Created March 1, 2017 23:14
Show Gist options
  • Select an option

  • Save towc/00ed828f69b999efa514b8f213446958 to your computer and use it in GitHub Desktop.

Select an option

Save towc/00ed828f69b999efa514b8f213446958 to your computer and use it in GitHub Desktop.
#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 );
}
#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
#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