Suppose the following:
struct POD1 { int a; };
struct POD2 : POD1 { int b; };
int main() {
POD2 p2 = POD2();
return 0;
}
Will both p2.a and p2.b equal 0 after p2 is defined? Basically I’m not sure if the value initialization rules also apply to base classes of POD types.
POD2 p2();
That does not do what you expect, but rather declares a function by the name
p2that takes no argument and returns aPOD2.Now, a slightly different case would be:
The right hand side of the expression
POD2()represents the creation of a temporary that is value-initialized [5.2.3/2]. Value-initialization for a user defined type with no user defined constructor is zero-initialization [8.5/7], and zero-initialization of that type will zero-initialize each one of the members and bases [8.5/5] guaranteeing that both members are 0.