Code: Select all

```
// Point.hpp
//
// Generic point class. The first coordinate is of one
// type and the second coordinate is of the second type.
//
// Version 1: Distance() function contains a std function as
// argument
//
// (C) Datasim Education BV 2006-2013
#ifndef Point_HPP
#define Point_HPP
#include <iostream>
#include <functional>
template <class X=double> class Point
{
private:
// The two coordinates
X m_x;
X m_y;
// The embedded algorithm (strategy) object; each object gets its own copy
std::function<double (const Point<X>& p1, const Point<X>& p2)> algo;
public:
typedef std::function<double (const Point<X>& p1, const Point<X>& p2)> FunctionType;
// Constructors & destructor
Point(const FunctionType& algorithm); // Default constructor
Point(const X& first, const X& second, const FunctionType& algorithm); // Constructor with coordinates
Point(const Point<X>& source); // Copy constructor
virtual ~Point(); // Destructor
// Selectors
const X& First() const; // Get first coordinates
const X& Second() const; // Get second coordinate
// Modifiers
void First(const X& val); // Set first coordinate
void Second(const X& val); // Set second coordinates
// Functions
double Distance(const Point<X>& p2) const; // Calculate distance
// Assignment operator
Point<X>& operator = (const Point<X>& source);
template <class X>
friend std::ostream& operator << (std::ostream& os, const Point<X>& p);
};
#include "Point.cpp"
#endif
```