Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          friends/point-with-operator-friend/point.cc - Class Point - implementation - including the implementation of operator<<.Lecture 4 - slide 36 : 40
Program 2

// The definition of operator<< and member functions of class Point.

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

// The operator is a friend of class Point:
std::ostream& operator<<(std::ostream& s, const Point& p){
  return s << "(" << p.x << "," << p.y << ")" ;
}


Point::Point(double x_coord, double y_coord): x(x_coord), y(y_coord){
}

Point::Point(): x(0.0), y(0.0){
}

double Point::getx () const{
  return x;
}

double Point::gety () const{
  return y;
}

void Point::move(double dx, double dy){
    x += dx; y += dy;
}

double Point::distance_to(Point p){
    return sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
}