-
Notifications
You must be signed in to change notification settings - Fork 0
/
Point2D.cpp
85 lines (48 loc) · 1.74 KB
/
Point2D.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Point2D Class
// Damien MATTEI
#include "Point2D.hpp"
// implementations
template <class T> Point2D<T>::Point2D() : x(0), y(0) {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# constructor " << this->display() << " #" << endl;
#endif
}
template <class T> Point2D<T>::Point2D(T x,T y) : x(x), y(y) {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# constructor " << this->display() << " #" << endl;
#endif
}
template <class T> Point2D<T>::~Point2D() {
#ifdef DISPLAY_CONSTRUCTOR
cout << "# destructor " << this->display() << " #" << endl;
#endif
}
template <class T> string Point2D<T>::display(void) {
std::stringstream stream;
//stream << "Point2D@" << std::setfill ('0') << std::setw(sizeof(long)*2) << std::hex << (long)this << "(" << x << "," << y << ")";
stream << "Point2D @" << " 0x" << std::hex << (long)this << " " << *this;
//return std::string("Point2D@") + std::to_string((long)this) + std::string("(") + std::to_string(x) + std::string(",") + std::to_string(y) + std::string(")");
return stream.str();
}
template <class T> ostream& operator<< (ostream &out, Point2D<T> &p2d)
{
out << "(" << p2d.x << ","
<< p2d.y << ")";
return out;
}
// copy constructor
template <class T> Point2D<T>::Point2D(const Point2D<T> &onePoint2D) {
x=onePoint2D.x;
y=onePoint2D.y;
#ifdef DISPLAY_CONSTRUCTOR
cout << "# copy constructor Point2D " << &onePoint2D << " => " << this << " " << *this << " #" << endl;
#endif
}
// equality operator
template <class T> bool Point2D<T>::operator== (const Point2D<T> &p2d) {
return (x==p2d.x) && (y==p2d.y);
}
template class Point2D<double>;
template class Point2D<int>;
template class Point2D<float>;
template ostream& operator<< (ostream &out, Point2D<double> &p2d);