这是把struct当成类来说的。如果struct里只有基础类型的变量(c语言里的结构体)。就不一样了,struct定义的东西可以使用mem开头的那些函数,class则不行。
[/quote]
这种东西在 C++ 里叫 standard-layout class 。他需要满足的条件很多,但是与他用 struct 或 class 定义无关。
9.3 Class members
14 Nonstatic data members of a (non-union) class with the same access control (Clause 11) are allocated so
that later members have higher addresses within a class object. The order of allocation of non-static data
members with different access control is unspecified (11). 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).
只要求访问控制相同的成员变量,后定义的地址高于先定义的。对是否连续没有要求。对不同访问控制的如何分布没有要求。
在 C++ 里, struct 和 class 没有除了默认访问控制不一样,没有其它区别。