Week 10
Lecture slides (Classes Part 2)
Constructors
Note: correction; the default constructor does not initialize variables.
struct S {
int i;
}
int main() {
S s;
cout << s.i << endl; // this is undefined behaviour, 'i' has not been initialized
}
Synthetic Default Constructor and Initializer Lists
Converting Constructor
Note: correction; constructors with default parameters work in the same way as functions with default parameters. Clock("11:11:PM")
will invoke the string conversion constructor, not the three-argument constructor because the three-argument constructor requires that its first argument is an int
(not a string
).