My question somewhat overlaps with this and several other similar ones. Those have some great answers, but I've read them and I'm still confused, so please don't consider this question a duplicate.
So, I have the following code:
class A {
public: int _a;
}
void main()
{
A inst1;
A* inst2 = new A;
A* inst3 = new A();
}
_a
is left uninitialized in inst1
and inst2
and is initialized to 0
in inst3
.
Which initialization is called which, and why does the code work as it does? Please take into I account I don't have a C++ 03 standard at hand, but I have the last C++ 11 draft (I'm programming by '03 standard, though), so quotations of the '03 standard or references to '11 are most welcome.
P. S. The original task behind this research was to correctly zeto-initialize a member of arbitrary template type T
.