If there is no initializer for an object, the object is default initialized [dcl.init]/12. If the initializer is (), the object is value initialized [dcl.init]/11. Default initialization of an object of class type (like std::vector<int>) invokes the default constructor while default initialization for an object of type int means no initialization [dcl.init]/7. Value initialization will also call the default constructor for objects of class type that have one (like std::vector<int> does), but for objects of type int, value initializtion means zero initialization [dcl.init]/8. And zero initialization for an int does actually mean that the int is initialized to zero [dcl.init]/6…
As has already been pointed out in the comments,
int w();
and
std::vector<int> y();
are not in fact definitions of a local variable, but rather declarations of two functions w and y that take no arguments and return an int and an std::vector<int> respectively (the infamous most vexing parse). Nevertheless, there are cases where it is possible to use () as an actual initializer, so let's modify your example a bit to demonstrate the behavior you were asking about:
class Foo
{
int w;
std::vector<int> y;
Foo()
: w(), // value initialized == zero initialized for int
y() // value initialized == default initialized for std::vector<int>
{
int x; // default initialized == uninitialized for int
std::vector<int> z; // default initialized
}
};
zdoes have its default constructor called, its just not obvious. Also, withyandwI'm pretty sure you declared a function, not a variable.int w();is a declaration for a function namedwwithout parameters and returningint. It is not a variable definition. Similarlyyis declared as function returningstd::vector<int>without parameters. I think you might want to use{}instead of()to demonstrate your question.