![]() ![]() | templates/vers6/point.h - The general class template Point followed by the specialized one. | Lecture 6 - slide 11 : 46 Program 1 |
// First the general Point template class. template<class C> class Point; template<class C> std::ostream& operator<<(std::ostream& s, const Point<C>& p); template<class 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); friend std::ostream& operator<< <>(std::ostream&, const Point<C>&); }; // A funny 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>&); };