Phlip wrote:
[color=blue]
> Rolf Magnus wrote:
>[color=green]
>> See
http://www.parashift.com/c++-faq-lit....html#faq-26.7[/color]
>
> The private made it non-POD.[/color]
Yes, and the presence of a user-defined constructor.
[color=blue]
> Why did I hear once that "the order of members is defined between access
> specifiers"?[/color]
You're probably thinking of this:
================================================== ==================
Nonstatic data members of a (non-union) class declared without an
intervening access-specifier are allocated so that later members have
higher addresses within a class object. The order of allocation of
nonstatic data members separated by an access-specifier is unspecified
================================================== ==================
So the answer to the OP would be "yes" for both a POD and his example class.
The members would indeed be in same order as they appear in the source
code.
[color=blue]
> Without private POD members, that just means the compiler can
> re-order between 'public:' and 'public:'.[/color]
Well, that rule isn't specific to PODs. It applies to all classes.
[color=blue][color=green][color=darkred]
>>> Please write simple code that works, and do not memcpy() this data, or
>>> the equivalent.[/color]
>>
>> Well, if it was a POD class, using memcpy() on it would be safe. That's
>> one of the reasons why POD classes are defined the way they are.[/color]
>
> Students should be advised against abusing PODs. Don't declare a POD just
> because "I have a bunch of bits here and I want them over there, too".
> Prefer high-level language features.[/color]
Right. I just wanted to make clear that memcpy is guaranteed to work for POD
types (and only for those).