开发者

C++ pod initialization via default c'tor

Consider this POD:

struct T
{
   int i;
   char c;
};

In which C++ standard was the requirement of POD members be initialize开发者_运维百科d 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.


What you're talking about is properly called "value initialization". It was introduced in C++03 (it's defined at §8.5/5, in case you want to look at the details).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜