Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          shared-pointers/raw-ptr2.cc - Similar program with raw pointers.Lecture 4 - slide 15 : 40
Program 11

// Similar program - with raw pointers

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

using namespace std;

int f(){
  Point *pp1{new Point{1,2}},
        *pp2{new Point{3,4}},
        *pp3;

  cout << *pp1 << endl;    // (1,2)
  cout << *pp2 << endl;    // (3,4)

  pp1 = nullptr;

  pp3 = pp2;               // both pp3 and pp2 refer to (3,4).
  pp3->displace(1,1);      // displace point pointed to by pp3

  cout << *pp2 << endl;    // (4,5) - Point pointed to by pp2 has moved!

  cout << "Exit f" << endl;  
}

int main(){
  f();
  cout << "After f()" << endl;
  // Both points (1,2) and (3,4) are still on the heap.
}