// The implementation of the Point template class. #include #include #include "point.h" // Default contructor template Point::Point() { for (int i = 0; i < dim; i++) values[i] = def; } // The get method access dimension i of the point template C Point::get(int i) const{ if (i >= 1 && i <= dim) return values[i-1]; else throw PointDimProblem(); } // Move the point by means of a vector of int. template Point& // deltas is a vector Point::move(const std::vector& deltas){ for (int i = 0; i < dim; i++) values[i] += deltas[i]; return *this; } // Distance to method - Using some funny norm: template double Point::distance_to(Point p){ double temp = 0.0; for (int i = 0; i < dim; i++) temp += std::abs(values[i] - p.values[i]); return temp; } // The << operator for points. template std::ostream& operator<< (std::ostream& s, const Point& p){ s << "("; for(int i = 0; i < dim-1; i++) s << p.values[i] << ", "; s << p.values[dim-1]; s << ")" << std::endl; return s; }