templates/vers4-f14/point.h - A type parameterized variant of class Point - point.h. | Lecture 5 - slide 34 : 40 Program 1 |
// Multi dimensional point. The dimension and a default value is supplied as a template parameter. // Defaults are provided for all three template parameters. #include <vector> template<typename C, int dim, C def> class Point; template<typename C, int dim, C def> std::ostream& operator<< (std::ostream& s, const Point<C,dim,def>& p); class PointDimProblem{}; template<typename C = int, int dim = 3, C def = 0>class Point { private: C values[dim]; // An array of C values public: Point(); C get (int i) const; Point<C, dim, def>& move(const std::vector<int>&); double distance_to(Point<C, dim, def>); friend std::ostream& operator<< <> (std::ostream&, const Point<C, dim, def>&); };