Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Use of constructors - with automatic variables of class type.Lecture 3 - slide 8 : 36
Program 3
//Point(): (0,7)        Point(double x): (x, 20)      Point(double x, double y): (y, y)       Point(Point& p) (p.x+1, p.y+2) 
//Reveal...

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

using namespace std;

int f(){
  Point p;
  cout << "Point p: " << p << endl;   // (0,7)
  
  Point r(11.0, 12.0);
  cout << "Point r: " << r << endl;   // (11,12)

  Point q;
  q = r;                              // default assignment - bit-wise copying, no use of copy constructor
  cout << "Point q: " << q << endl;   // (11,12)

  Point s(p);                         // The copy constructor used
  cout << "Point s: " << s << endl;   // (1,9)

  Point t(3.0);                       // Point(double) used
  cout << "Point t: " << t << endl;   // (3,20)

  Point u = t;                        // Another way to use the copy constructor, via an initializer
  cout << "Point u: " << u << endl;   // (4,22)


  Point ap[10];                       // The default constructor used 10 times
  for(int i = 0; i < 10; i++)         // (0,7) ten times
     cout << "ap[" << i << 
     "]: " << ap[i] << endl;  
}

int main(){
  f();
}