| templates/vers2-f14/point.cc - The implementation of the template class Point - point.cc. | Lecture 5 - slide 33 : 40 Program 2 |
// point.cc
#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(0.0), y(0.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; // Implicitly assume that + applies to C values
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)); // Similar assumptions for - and *
}
template<typename C> std::ostream& operator<<
(std::ostream& s, const Point<C>& p){
return s << "(" << p.getx() << "," << p.gety() << ")" ;
}