| constructors/move/prog-commented.cc - Same program with more comments. | Lecture 4 - slide 10 : 40 Program 4 |
//Commented version of the previous program.
//Point(): (0,7) Point(double x): (x, 20) Point(double x, double y): (x, y)
//Point(Point& p) (p.x+1, p.y+2) Point(Point&& p) (p.x-3, p.y-4)
#include <iostream>
#include "point.h"
using namespace std;
//A Point identity function - revealing the parameter p by printing on standard output.
Point pf(Point p){
cout << "Inside pf: Parameter: " << p << endl;
return p;
}
int f(){
Point p;
cout << "Point p: " << p << endl; // (0,7)
// COPYING INTO, MOVING OUT FROM:
Point q = pf(p); // Passing p to pf via copy constructor: (1,9)
cout << "Point q: " << q << endl; // (-2,5) - because pf handles return via the move constructor.
// BITWISE PASSING INTO, MOVING OUT:
Point r = pf(Point{10,12}); // Constructing point (10,12) via Point(double,double). Passing it bitwise!?
cout << "Point r: " << r << endl; // (7,8). Returning via use of move constructor.
// MOVING INTO, MOVING OUT:
Point s = pf(move(Point{10,12})); // Passing Rvalue point (10, 12) to pf via forced used of move constructor (7,8).
cout << "Point s: " << s << endl; // (4,4) - because pf handles return via the move constructor.
}
int main(){
f();
}