Karl Heinz Buchegger said:
They don't
you can:
#include <iostream>
using namespace std;
class A
{
public:
int m_n;
};
A does not have a user-defined constructor. The compiler generated one
will be similar to the following:
A::A() {}
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.
int main()
{
A* pA = new A;
A* pB = new A();
Both call the default constructor.
Here pA->m_n is left uninitialized while
pB->m_n should be default initialized.
*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.
VC++ 6.0 however gets this wrong and I suspect that
most compiler get this wrong. In other words: don't
depend on it.
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.
Ali