I have the following warning:
warning C4345: behavior change: an object of POD type constructed with
an initializer of the form () will be default-initialized
Should I care (if yes, why?)
Should I worry (if no, under what conditions should I worry ? - if yes why?)
I looked on the MS site for help with this warning but the examples
giving are pretty scant and info about this (via Google) is generally
scant ...
adebaene@club-internet.fr - 27 Jul 2006 11:21 GMT
> I have the following warning:
>
[quoted text clipped - 7 lines]
> giving are pretty scant and info about this (via Google) is generally
> scant ...
Show us a minimal code snippet that give you this warning....
Arnaud
MVP -VC
Bo Persson - 27 Jul 2006 16:19 GMT
>I have the following warning:
>
> warning C4345: behavior change: an object of POD type constructed
> with an initializer of the form () will be default-initialized
>
> Should I care (if yes, why?)
Yes, because this is what the compiler should do.
> Should I worry (if no, under what conditions should I worry ? - if
> yes why?)
No, it is actually an improvement, as this is required by the
standard. Earlier versions did't do it right, or was produced before
there was a standard.
Bo Persson
Doug Harrison [MVP] - 27 Jul 2006 16:25 GMT
>I have the following warning:
>
>warning C4345: behavior change: an object of POD type constructed with
>an initializer of the form () will be default-initialized
>
>Should I care (if yes, why?)
This means it will be zero-initialized, as required by the standard. For
example, the following should cause the created objects to be
zero-initialized:
int* p = new int();
struct X
{
int x;
};
X* q = new X();
However, the following syntax (note the lack of parens) leaves the
variables uninitialized;
int* p = new int;
X* q = new X;
>Should I worry (if no, under what conditions should I worry ? - if yes why?)
It sounds like you weren't expecting any particular value (and if you were,
the only one you had any right to expect was zero, in which case, be happy,
because now you'll get it reliably), so zero should be as good as any. The
only downside is that it takes a little extra code to accomplish this.

Signature
Doug Harrison
Visual C++ MVP