C ++ pod initialization by default c'tor

Consider this POD:

struct T { int i; char c; }; 

In which C ++ standard did POD elements need to be initialized to zero through the default c'tor (or was it in the standards from the very beginning)?

Yes, this means that without c'tor specified by the user, "i" and "c" will both be initialized to 0. See http://msdn.microsoft.com/en-us/library/80ks028k%28VS.80% 29.aspx

+4
source share
2 answers

I do not know if I understood your question correctly or not.

that is, without c'tor specified by the user, 'i' and 'c' will be initialized to 0.

Not necessary.

For instance:

 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 what you are looking for. It was introduced in C ++ 03.

+5
source

What you are talking about is correctly called value initialization. It was introduced in C ++ 03 (it is defined in ยง8.5 / 5 if you want to see the details).

+5
source

All Articles