"Mark" <> wrote...
> >
>> Yes. Why are you surprised? To initialise the variable you need
>> to write
>>
>> unsigned int i(42); // or whatever value you prefer
>>
>
> _because in the context of the previous post_,
>
>> Does that mean that, on built-in types (e.g. int), "default
>> initialization" (as described in 8.5) is performed?
>
> Yes. Effectively, it means that for POD types (which includes the
> built-in types) the values are zero initialized.
In the 'valarray's constructor, yes. Just like in the 'vector's
constructor, for example.
> I was expecting
>
> unsigned int i;
>
> to have a default initialiser of zero.
WHY? The 'i' variable here is not _default_-initialised. It is
_uninitialised_. In the statement above there is no _initialiser_.
Read 8.5/9, it should be clear enough.
> Basically I just need to clear up my understanding of the standard
> behaviour, and work out where my misunderstanding lies.
Do you have a copy of the Standard? Then read 8.5 carefully. If
you don't have a copy of the Standard, how do you expect to clear
up your understanding of it?
> In practice , I always endeavour to explicitly initialise my vars
> re: best practice, so it would'nt normally be a problem.
That's called "avoiding the issue".
V
|