-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoint.h
39 lines (32 loc) · 1.14 KB
/
point.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef POINT_H
#define POINT_H
#include<ostream>
// Points on 2d grid
class Point {
// Overloaded operators for convenience. You must be careful with
// friend functions if abused you can easily violate encapsulation.
// Functions that can be made friends are tightly related to concept
// of the object.
friend std::ostream & operator<<(std::ostream &os, const Point& p);
friend Point operator+ (const Point &lhs, const Point &rhs);
friend Point operator- (const Point &lhs, const Point &rhs);
friend double sqrDist(const Point &p1, const Point &p2);
public:
Point();
Point(int x, int y);
// Will make use of implicit copy constructor and assignment operators
// for shallow copy, which is fine since there is no dynamically
// allocated memory.
int x() const;
int y() const;
void set(int x, int y);
// overloaded comparison operator, two points are equal
// if both their elements are equal
bool operator==(const Point &other);
bool operator==(const Point &other) const;
bool operator!=(const Point &other);
bool operator!=(const Point &other) const;
private:
int m_x, m_y;
};
#endif//POINT_H