Lecture overview -- Keyboard shortcut: 'u'  Previous page: More about constructors -- Keyboard shortcut: 'p'  Next page: Destructors -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 8 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Use of constructors

We illustrate the use of overloaded constructors - both with 'static allocation' and 'dynamic allocation'

In order to distinguish the use of the individual constructors they carry out 'funny Point initializations'

  • Four funny Point constructors:

    • Point(): (0,7) - default constructor

    • Point(double d, double e): (d,e)

    • Point(double d): (d,20)

    • Point(Point& p): (p.x+1.0, p.y+2.0) - copy constructor

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/point.hClass Point with a variety of constructors.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/point.ccFunny implementations of constructors.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/reordered/prog2.ccUse of constructors - with automatic variables of class type.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/reordered/program-outputActual program output.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/prog2-more.ccAn additional Point construction attempt - a trap.


Go to exerciseUse of constructors with object on the free store