Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The implementation of the template class Point - point.cc.Lecture 5 - slide 4 : 39
Program 2
#include <cmath>
#include <iostream>
#include "point.h"

template<class C> Point<C>::Point(C x_coord, C y_coord):
   x(x_coord), y(y_coord){
}

template<class C> Point<C>::Point(): x(0.0), y(0.0){
}

template<class C> C Point<C>::getx () const{
  return x;
}

template<class C> C Point<C>::gety () const{
  return y;
}

template<class C> Point<C>& Point<C>::move(C dx, C dy){
  x += dx; y += dy;  // Implicitly assume that + applies to C values 
  return *this;
}

template<class C> double Point<C>::distance_to(Point p){
  return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}


template<class C> std::ostream& operator<< 
                        (std::ostream& s, const Point<C>& p){
  return s << "(" << p.getx() << "," << p.gety() << ")" ;
}