Skip to content

Instantly share code, notes, and snippets.

@mister11
Created September 10, 2014 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mister11/3061e206a4398f77a526 to your computer and use it in GitHub Desktop.
Save mister11/3061e206a4398f77a526 to your computer and use it in GitHub Desktop.
int main(int argc, char** argv) {
Point * p = new Point(1, 42);
cout << *p << endl;
return 0;
}
#include "Point.h"
Point::Point() : Point(0, 0) {
}
Point::Point(double x, double y) : x(x), y(y) {
}
double Point::getX() const {
return this->x;
}
double Point::getY() const {
return this->y;
}
void Point::setX(double x) {
this->x = x;
}
void Point::setY(double y) {
this->y = y;
}
inline std::ostream& operator<<(std::ostream& os, const Point& obj) {
os << "(" << obj.getX() << "," << obj.getY() << ")";
return os;
}
#include <iostream>
#ifndef POINT_H_
#define POINT_H_
class Point {
public:
Point();
Point(double x, double y);
double getX() const;
double getY() const;
void setX(double);
void setY(double);
friend std::ostream& operator<<(std::ostream& os, const Point& obj);
private:
double x;
double y;
};
#endif /* POINT_H_ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment