templates/vers6/point.h - The general class template Point followed by the specialized one. | Lecture 5 - slide 39 : 40 Program 1 |
// First the general Point template class. template<typename C> class Point; template<typename C> std::ostream& operator<<(std::ostream& s, const Point<C>& p); template<typename C>class Point { private: C x, y; public: Point(C, C); Point(); C getx () const; C gety () const; Point<C>& move(C, C); double distance_to(Point<C>); friend std::ostream& operator<< <>(std::ostream&, const Point<C>&); }; // A funny complete, specialization for Point<char>. All details are inlined in this version. template<>class Point <char>{ private: char x, y; public: Point(char c1, char c2): x(c1), y(c2) {} Point(): x('a'), y('z'){} char getx () const {return x;} char gety () const {return y;} Point<char>& move(char c1, char c2){x = c1; y = c2; return *this;} double distance_to(Point){return 7.0;} friend std::ostream& operator<< <>(std::ostream&, const Point<char>&); };