考虑一下这个POD:
struct T
{
int i;
char c;
};
Run Code Online (Sandbox Code Playgroud)
在哪个C++标准中,POD成员的要求是通过默认的c'tor引入(或者从标准开始)到初始化为零?
是的,这意味着没有用户指定的c'tor,'i'和'c'都将初始化为0.请参阅http://msdn.microsoft.com/en-us/library/80ks028k%28VS.80%29. ASPX
我不知道我是否理解你的问题.
这意味着没有用户指定的c'tor,'i'和'c'都将被初始化为0.
不必要.
例如:
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.
Run Code Online (Sandbox Code Playgroud)
准确地说value initialization(C++ 03 Section $ 8.5/5)是你正在寻找的东西.它是在C++ 03中引入的.