Consider the following class with member initializer list:
class A {
public:
A() : a {b} {
// do something
}
private:
int a {1};
int b {2};
};
The compiler issues a warning that b is used uninitialized in the member initalizer list. This would mean, the member b has been already created but not initialized yet?
Thus, can we assume the following order of execution?
- call constructor A()
- int a; (create memory for a)
- int b; (create memory for b)
- a = b; (compiler warning)
- b = 2; (assign default 2 to b)
- execute constructor's block
This would mean, we actually do not initialize but assign values in step 4 and 5?
EDIT: If so, what is the advantage of an initializer list, when assignments can also be done in the block after the members have been created prior entering the block?