| constants/const-ptr-1-valid-feb-14.cc - Only the valid parts of the program from above - compiles. | Lecture 2 - slide 28 : 29 Program 2 |
// Compilable parts of previous program.
#include <iostream>
#include <string>
#include "point.h"
int main(){
Point p(1,2); // p is a Point. It can be moved (by mutation).
p.move(0,1);
const Point q(3,4); // q is a constant point.
const Point *r = &p; // r is pointer to a constant point
Point const *rr = &p; // rr is pointer to a constant point - fully equivalent to definition or r above.
Point *const s = &p; // s is a constant pointer to 'the point p'. *const is a 'declarator operator'.
s->move(1,2); // OK.
Point const* w = &p; // w is a pointer to a constant point. const* is NOT a 'declarator operator'.
// Point const ... and const Point means the same.
const Point *const t= &p; // t is a constant pointer to a constant point.
Point const *const v= &p; // Same as definition of t (Point and const has just been reversed).
}