// point.h - Playing with constructors, destructors, and having pointers. #ifndef POINT_H_ #define POINT_H_ class Point { int x; int y; char *name; public: Point(int n = 0): x(n), y(n), name(NULL){} // Constructor Point(int a, int b, char * s): x(a), y(b) // Constructor { name = new char[1+strlen(s)]; strcpy (name, s); } Point(Point& a) // Copy constructor { x = a.x; y = a.y; name = new char[1+strlen(a.name)]; strcpy(name, a.name); } ~Point() // Destructor { delete [] name; cout << "I am the pitiless destructor\n"; } Point& operator=(const Point& b) // Copy Assignment operator { x = b.x; y = b.y; if (name != NULL) { delete [] name; } name = new char[1+strlen(b.name)]; strcpy(name, b.name); return *this; } friend ostream& operator<<(ostream& s, const Point& p) { s << p.x << ' ' << p.y << ' ' << p.name; return s; } friend bool operator<(const Point& a, const Point& b) { return ((a.x*a.x + a.y*a.y) < (b.x*b.x + b.y*b.y)); } friend bool operator==(const Point& a, const Point& b) { return ((a.x*a.x + a.y*a.y) == (b.x*b.x + b.y*b.y)); } }; // Sort the array a with n elements on basis of length of pointers void sort(Point *a[], int n); // Print content of an array a with n elements void printPointArray(const Point * const a[], int n); #endif