Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          destructors-2a/prog.cc - A sample program - now without memory leaks.Lecture 4 - slide 12 : 40
Program 6

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

using namespace std;

int f(){

  Point p, q,                         
        r(11.0, 12.0),
        ap[2],
        *s = new Point(13.0, 14.0);                


  cout << "Point p: "      << p << endl;      // (0,0)
  cout << "Point q: "      << q << endl;      // (0,0)
  cout << "Point r: "      << r << endl;      // (11,12)
  cout << "Point ap[0]: "  << ap[0] << endl;  // (0,0)
  cout << "Point ap[1]: "  << ap[1] << endl;  // (0,0)
  cout << "Point *s: "     << *s << endl;     // (13,14)

  delete s;

  // The Point destructor is called 6 times in total on exist from f.
  // No leaks any more.
  // 5 implicit calls for p, q, r, ap[0], and ap[1] respectively.
  // 1 explicit call via delete s.
}

int main(){
  f();
}