The default constructor for int does nothing.
In the above, on line 5 you are not (even though it looks that way) default constructing a.
It's a subtle difference.
It had to be added to the language to allow things like:
1 2 3 4 5 6
|
template< typename T >
class Foo {
T x;
public:
Foo() : x() {}
};
|
to work consistently for all types T. Obviously putting an explicit "0" there would
mean x has to be constructible from an int. Therefore things like string would not
work.
Without the subtlety, then upon construction of a Foo<int>, x is uninitialized but
upon construction of a Foo<string>, x would be initialized to a known value.
The language had to solve this problem, so the solution was to allow x() in the
initializer list to initialize x to zero (false) for all POD types, including pointers.