Lecture overview -- Keyboard shortcut: 'u'  Previous page: Functions outside classes -- Keyboard shortcut: 'p'  Next page: Constructors - initialization versus assignment -- 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 5 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Constructors

The name of a constructor is the same as the name of its class or struct.

Constructors in C++ are in many ways similar to constructors in C# and Java

  • The C++ Programming Language: Page 226, 247, 270
 

  • Initialization of class data members with member initializers

    • Special syntax for initialization

    • Placed between the constructor header and the body

    • Passes arguments to the constructors of the members

    • Constructor chaining is not supported in C++

      • Instead, the constructors may delegate the initialization work to a (private) method

y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors-point-rectangle/boiled-down-for-notes/point.hThe Point class.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors-point-rectangle/boiled-down-for-notes/point.ccImplementation of the Point class constructors.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors-point-rectangle/boiled-down-for-notes/rect.hThe Rectangle class.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors-point-rectangle/boiled-down-for-notes/rect.ccImplementation of the Rectangle class constructors.


y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors-point-rectangle/boiled-down-for-notes/prog.ccSample Rectangle constructions.


Go to exerciseMethods in class Point and class Rectangle
y:/Kurt/Files/Advanced-programming-cpp/cpp/kn/constructors/point-constructors-problems.ccIllustration of legal and illegal member initializers - constructor chaining is not supported.