Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          templates/vers6/point.cc - The implementation of the template class Point - point.cc - nothing interesting here.Lecture 5 - slide 39 : 40
Program 2

// The general implementation of the Point template class.

#include <cmath>
#include <iostream>
#include "point.h"

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

template<typename C> Point<C>::Point(): x(C()), y(C()){    // int() is 0 ...
}

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

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

template<typename C> Point<C>& Point<C>::move(C dx, C dy){
    x += dx; y += dy; 
    return *this;
}

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


template<typename C> std::ostream& operator<<
                          (std::ostream& s, const Point<C>& p){
  return s << "(" << p.x << "," << p.y << ")" ;
}