Consider this POD:
struct T
{
int i;
char c;
};
In which C++ standard was the requirement of POD members be initialized to zero via default c'tor introduced (or was it in the standards from the beginning)?
Yes, that means without user specified c'tor, 'i' and 'c' will both be initialized to 0. See http://msdn.microsoft.com/en-us/library/80ks028k%28VS.80%29.aspx
I don't know if I have understood your question properly or not.
that means without user specified c'tor, 'i' and 'c' will both be initialized to 0.
Not necessarily.
For example:
T x; // `i` and `c` are uninitialized
T *ptr = new T; // `i` and `c` are uninitialized
T *pptr = new T(); //`i` and `c` are zero initialized as `T()` implies value initialization
T x(); // x is a function returning a type T and taking no arguments.
To be precise value initialization
(C++03 Section $8.5/5) is something you are looking for. It was introduced in C++03.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With