> What is default initialization?
a. For a POD class type or a built-in POD type like
int, initialise to an indeterminate value (do nothing).
b. For a non-POD class type, call a default constructor which provides the initialised value.
c. For an array type, default initialise every element of the array.
> when does it occur?
a. A variable (with automatic, static, or thread-local storage duration) is declared with no initializer.
eg.
void foo() { int x ; /*x is default initialised */ }
b. An object is created by a new-expression with no initializer
eg.
void foo() { int* x = new int ; /*the object of type int is default initialised */ }
c. when a base class or a non-static data member of a class is not explicitly initialised in a constructor initializer list or via a default-member-initialiser.
eg.
1 2 3
|
struct A { int x ; std::string y ; };
void foo() { A a ; /*members x and y are default initialised */ }
|