Created
September 10, 2014 00:54
-
-
Save mister11/3061e206a4398f77a526 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
int main(int argc, char** argv) { | |
Point * p = new Point(1, 42); | |
cout << *p << endl; | |
return 0; | |
} |
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 "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; | |
} |
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 <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