看板 C_and_CPP 關於我們 聯絡資訊
推 cplusplus:原因我是忘了 找看看C++ Object Model吧 裡面有提到 您好, 在您提的書我剛找來翻了 :) 因為書中提到的部份是根據spec來的, 所以我摘spec中對於data member順序配置的部份出來. 大意是說, 同一access下有要求先宣告先配置, 但不同access下的順序沒有明定. C++98與C++03的定義一樣, 內文如下: 9.2 Class members 12. Nonstatic data members of a (non-union) class declared without an intervening access-specifier are allocated so that later members have higher addresses withing a class object. The order of allocation of nonstatic data members separated by an access-specifier is unspecified (11.1). 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 classese (10.1). 然後作者提到, 雖然不同access下的順序沒有定義, 但整個class仍是要 配成連序空間. 原文在 Inside The C++ Object Model (3.2 Data member layout) 感謝cplusplus提供書藉資訊 :p -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.138.150.96
cplusplus:當然不管怎樣都會連續配置 只是不能亂搞記憶體 :) 06/14 20:46