constructors/prog2-modern.cc - An additional Point construction attempt - with use of uniform default initialization. | Lecture 4 - slide 8 : 40 Program 6 |
#include <iostream> #include "point.h" using namespace std; int f(){ Point p, q, // The default constructor is used for both p and q q1{}, // Default initialization. The same as for p and q, but prefer {}. r{11.0, 12.0}, // Point(double,double) used s{p}, // The copy constructor used t{3.0}, // Point(double) used u = t, // Another way to use the copy constructor. ap[10]; // The default constructor used 10 times q = r; // default assignment - bit-wise copying, no use of copy constructor cout << "Point p: " << p << endl; // (0,7) cout << "Point q: " << q << endl; // (11,12) cout << "Point q1: " << q1 << endl; // (0,7) cout << "Point r: " << r << endl; // (11,12) cout << "Point s: " << s << endl; // (1,9) cout << "Point t: " << t << endl; // (3,20) cout << "Point u: " << u << endl; // (4,22) for(int i = 0; i < 10; i++) // (0,7) ten times cout << "ap[" << i << "]: " << ap[i] << endl; } int main(){ f(); }