Do these members have unspecified ordering?

前端 未结 1 1167
天命终不由人
天命终不由人 2020-11-30 09:32

A colleague told me that, in the following type, all members have unspecified ordering in memory (relative to one another).

I doubt this, because they all have the s

相关标签:
1条回答
  • 2020-11-30 10:08

    Your colleague is correct for C++03:

    [C++03: 9.2/12]: 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 (11.1). [..]

    But you are correct for C++11:

    [C++11: 9.2/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). [..]

    (Spot the difference.)

    0 讨论(0)
提交回复
热议问题