Lecture overview -- Keyboard shortcut: 'u'  Previous page: Constructors - C++11 -- Keyboard shortcut: 'p'  Next page: More about constructors -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Alphabetic index  Help page about these notes  Course home    Abstraction Mechanisms, Part 1 - slide 8 : 41

Constructors - initialization versus assignment

The main task of a constuctor is to initalize data members

In C++ initialization and assignment must be distinguished

Initialization is controlled by copy constructors, assignment by operator= overloads

rect.h
The Rectangle class - header file.
rect-ini.cc
Rectangle constructors - with initialization.
rect-ass.cc
Rectangle constructors - with default initialization and subsequent assignments.

Const data members and references must be initialized - they cannot be assigned in the body of the constructor

Always prefer explicit initialization - the rules for implicit initialization are (too) complicated