I recently ran into a problem with one of my classes because I did not set a pointer to NULL in my constructor initialization list, and therefore it contained garbage when I ran the program.
However, although I know that instances of a built-in type declared on the stack but not initialized will contain random values, I was sure I would read somewhere that, since class members not explicitly placed on the constructor initialization list have your default constructors, for built-in types this will also happen by inserting code similar to the pseudo-constructor that will be on most platforms, set them to zero. I also thought that I read somewhere in “Thinking in C ++” that under certain circumstances, before an object is built, its memory will be reset, however, I seem to be wrong in both cases.
Please, someone can confirm me,
a) Initialization of elements of a built-in type has something to do with whether a user-defined constructor is defined or not, b) it is always necessary to initialize elements of a built-in type manually, and
c) do any circumstances in which the storage of an object is reset before calling the constructor?
Also, examining this, I saw that the terms "default-initialised" and "zero-initialised" are used - is there a difference between the statement:
T a;
and
T a();
? I thought the first form was just used to prevent ambiguity when the second could be accepted by the compiler as a function declaration.
Thanks so much for your time,
stellarpower