Ron Natalie posted:
>
> "JKop" <> wrote in message
> news
Jf4d.31741$...
>> So what's "value intialization" and how is it different
from "default
>> initialization"?
>>
>
> To understand value initialization, you have to
understand that while
> POD types have default initialization (zero
initialization), some times
> the default initialization is just omitted. [This I see
as a major
> defect in the language, but it makes it performance
compatible with C
> so it's hard to convince people of the stupidity.]
>
> The problem is that types such as:
> struct S {
> int i;
> T t;
> };
>
> Get different behavior in the old standard based on the
type of T (if T
> is POD then S is POD and you get zero initialization and
i is hence
> zero initialized, if T is not POD, then i doesn't get
initialized
> because S's default constructor doesn't touch it).
>
> To fix this, most places where default initialization
occured are
> replaced with value initialization. And value
initialization rather
> than using "PODness" of a determining factor looks for
the presence of
> a user defined constructor to determine whether to
recursively
> value-initialize or to just run the consturctor...
>
Okay... I think I understand. Given:
struct Blah
{
int i;
std::string k;
};
With regard to the *old* standard, when you did:
Blah poo = Blah();
Then "poo.i" didn't get... let's just call it
"initialized".
But... with the new standard, when you do:
Blah poo = Blah();
then "poo.i" *does* get initialized.
BTW, Blah is a POD, right? I'd classify it as so in
anyway...
Would I be right in thinking that the following are the
factors which render a structure *no longer* a POD:
A) a constructor (including a copy constructor)
B) private or protected members
Well... if you look at Blah, it has neither, hence you can
define one as so:
std::string a("MONKEY!");
Blah poo = { 5, a };
And as such it's a POD... right?
-JKop