s*****k 发帖数: 604 | 1 C++标准里面对这个有规定吗?
比如先private再public,类似这样的规定
好像C里面struct里的各个field是不能变顺序的,
在内存里就是按着声明的顺序排的。有些语言可以
根据需要(例如alignment)调整各个field的顺序 |
c**a 发帖数: 316 | 2 声明的顺序吧。
【在 s*****k 的大作中提到】 : C++标准里面对这个有规定吗? : 比如先private再public,类似这样的规定 : 好像C里面struct里的各个field是不能变顺序的, : 在内存里就是按着声明的顺序排的。有些语言可以 : 根据需要(例如alignment)调整各个field的顺序
|
t****t 发帖数: 6806 | 3 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
(_class.access.spec_). Implementation alignment requirements might
cause two adjacent members not to be allocated immediately after each
other; so might requirements for space for managing virtual f |
a****l 发帖数: 8211 | 4 I believe the point of making class is exactly that you should not try to
figure out where they are in the memory.
【在 s*****k 的大作中提到】 : C++标准里面对这个有规定吗? : 比如先private再public,类似这样的规定 : 好像C里面struct里的各个field是不能变顺序的, : 在内存里就是按着声明的顺序排的。有些语言可以 : 根据需要(例如alignment)调整各个field的顺序
|
s*****k 发帖数: 604 | 5 我以前用过一个数值计算的C++的库,里面也用到lapack,
那里面就是假设 std::complex 和 fortan77里面的
complex16 的 memory layout是一样的。好像在大部分平台上
也确实如此。
【在 a****l 的大作中提到】 : I believe the point of making class is exactly that you should not try to : figure out where they are in the memory.
|