Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'                friends/point-with-friends-f15/prog.cc - The program including implementation of friend moving functions.Lecture 4 - slide 35 : 40
Program 3

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

using namespace std;

// Friend of Point. Mutate p.
void Move_relatively_1(Point &p, double dx, double dy){
  p.x += dx; p.y += dy;
}

// Friend of Point. Do not mutate p. Return moved copy of Point.
Point Move_relatively_2(const Point &p, double dx, double dy){
  return Point(p.x + dx, p.y + dy);             // point copied out
}

int main(){

  Point p(1,2), q(3,4), r, s;

  p.move_relatively(1,1);         // Mutate p, with the member function move.
  Move_relatively_1(q,1,1);       // Mutate q by the friend Move 1 - maybe misleading!
  r = Move_relatively_2(p,1,1);   // Make a moved point by the friend Move2.

                      // Which of the Moving abstractions do we prefer?

  cout << "Point p: " << p << endl;   // (2,3)
  cout << "Point q: " << q << endl;   // (4,5)
  cout << "Point r: " << r << endl;   // (3,4)
}