简体   繁体   English

为什么工会的成员具有不同的访问控制而不是标准布局?

[英]Why are unions which have members with differing access control not standard-layout?

§9.0 §9.0

7. A class S is a standard-layout class if it: 7.如果满足以下条件,则S类是标准布局的类:

(7.3) has the same access control (Clause 11 ) for all non-static data members, (7.3)对所有非静态数据成员具有相同的访问控制(条款11),

8 A standard-layout struct is a standard-layout class defined with the class-key struct or the class-key class . 8标准布局结构是用class-key结构或class-key class定义的标准布局类。 A standard-layout union is a standard-layout class defined with the class-key union . 标准布局联合是使用class-key union定义的标准布局类。

AFAICT, §9.0.7.3 exists because of §9.2.13 AFAICT,存在§9.0.7.3是因为存在§9.2.13

13 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. 分配了具有相同访问控制(第11条)的(非联盟)类的非静态数据成员,以便稍后的成员在类对象中具有更高的地址。 The order of allocation of non-static data members with different access control is unspecified (Clause 11 ). 未指定具有不同访问控制的非静态数据成员的分配顺序 (第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 ). 管理虚拟功能(10.3)和虚拟基类(10.1)的空间要求也可能如此。

However, this does not seem to apply to unions, as all (non-static data) members of a union have the same address. 但是,这似乎不适用于联合,因为联合的所有(非静态数据)成员都具有相同的地址。 Is this a defect in the standard? 这是标准的缺陷吗? Or is there some compelling reason why that I'm not seeing? 还是有一些令人信服的原因使我看不到?

在我看来,允许在union案例中使用多个访问说明符的好处并没有因不一致的代价和引入的其他单词而被抵消。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM