Lecture 4 - Slide 8 : 40
Use of constructors
We illustrate the use of overloaded constructors - using
funny Point initializations
Four funny
Point
constructors:
Point()
:
(0, 7)
- default constructor
Point(double x, double y)
:
(x, y)
Point(double x)
:
(x, 20)
Point(const Point& p)
:
(p.x+1.0, p.y+2.0)
- copy constructor
Class Point with a variety of constructors.
Funny implementations of the constructors.
Use of constructors - with local variables of class type.
Actual program output.
An additional Point construction attempt - a trap.
An additional Point construction attempt - with use of uniform default initialization.
Use of constructors with object on the free store