A
Andrey Tarasevich
Ali said:A does not have a user-defined constructor. The compiler generated one
will be similar to the following:
A::A() {}
That's how the _definition_ of the implicitly declared constructor will
look like, if the compiler actually decides to define it. The implicitly
declared constructor is implicitly defined _if_ _and_ _only_ _if_ it is
used in the program. But the truth is that it is not used in this
program. See below.
In other words, the compiler will not write the constructor like this:
A::A() : m_n() {}
which would be the equivalent of
A::A() : m_n(0) {}
The built-in types are never default constructed.
You are right, they aren't. But that's largely irrelevant in this case.
See below.
Both call the default constructor.
Wrong. Neither calls any constructors.
The first form leaves object uninitialized. No constructors called.
The second form performs default initialization, which is
zero-initialization in this case. This initialization is done
_directly_, it does not involve any constructor calls either.
*pA and *pB are both default constructed, but since the compiler
generated constructor does not initialize the built-in types, m_n
members are both left uninitialized.
Incorrect. 'pB->m_n' is zero. Default initialization took care of that.
None of those compilers are wrong if they don't initialize the
built-in members. They are not required to default-initialize built-in
types.
No, it is a known bug in MSVC++ 6. You are confused because you don't
understand the difference between two separate concepts in C++: the
concept of initialization and the concept of construction.