Phlip said:
What's the purpose of that rule if you should not treat them as a POD?
Good question.
private:
int a;
int b;
...
assert(&a + 1 == &b); // ?
assert(&a < &b); // ?
The first assertion would seem to imply you can treat them as an array -
if they pack tightly, too.
The next sentence after the one I quoted is:
==========================================================================
Implementation alignment requirements might cause two adjacent members not
to be allocated immediately after each other; so might requirements for
space for managing virtual functions (10.3) and virtual base classes
(10.1).
==========================================================================
So the compiler could e.g. choose to put a vtable pointer between a and b if
the class has virtual member functions.
What I have always been wondering about is the alignment. Is it guaranteed
that the alginment of a type is not larger than the type itself? I guess it
is, because otherwise, you couldn't put it in an array. But that would mean
that the first assertion is indeed guaranteed to be true if the class has
no virtual functions or virtual base classes.