templates/functions/point-norms-and-compare/point.cc - Member functions in class Point. | Lecture 5 - slide 37 : 40 Program 5 |
// Definition of members in template class Point. Notice the use of static members from the type P. #include <cmath> #include <iostream> #include "point.h" template<typename P>Point<P>::Point(double x_coord, double y_coord): x(x_coord), y(y_coord){ } template<typename P>Point<P>::Point(): x(0.0), y(0.0){ } template<typename P> double Point<P>::getx () const{ return x; } template<typename P> double Point<P>::gety () const{ return y; } template<typename P> double Point<P>::distance_to(Point<P> p){ return P::distance_to(*this,p); } template<typename P> bool Point<P>::less_than(const Point<P>& p){ return P::less_than(*this,p); } template<typename P> std::ostream& operator<<(std::ostream& s, const Point<P>& p){ return s << "(" << p.getx() << "," << p.gety() << ")" ; }