Is order in memory guaranteed for class private members in C++?
问题 class my_class_t { private: uint64_t field1; uint64_t field2; }; Is order of field1 and field2 guaranteed in memory by C++ Standard? UPD. Answers said that field2 it is, but &field2 may be not equal to &field1 + 1 . How to ensure that field2 will be immediately after field1 ? 回答1: They are guaranteed to have increasing addresses with respect to each other ([class.mem]/13): Nonstatic data members of a (non-union) class with the same access control (Clause [class.access]) are allocated so that