* Michael Tsang:
I'm very confused among different types of initializations:
All that you need to remember and that you can rely on is
* Static duration objects are zero initialized before anything else.
* Apart from that, you get the initialization that you specify.
E.g. if you have defined at least one constructor for your class, then a
constructor will be called for every instance of that class (except if one does
nasty low-level things).
And e.g., when you write
T* const p = new T();
then the parenthesis says that you want initialization, and for each member of T
you get the initialization that is available (zeroing or a constructor call).
If you omit the parenthesis then you say that you don't care about
initialization and that you will be happy with whatever initialization that T
defines, if any.
Also, how does zero-initializing a reference make sense?
The standard defines it thusly, in ?8.5/5: "no initialization is performed".
It's that simple.
Of course since you can't use the reference without UB before it's been properly
initialized, a compiler may choose to represent a namespace level reference as a
pointer and zero the pointer value so that &r, if it didn't do any of all the
arbitrary things that the UB allows, would yield a null-pointer at this time.
Cheers & hth.,