gpt4 book ai didi

c++ - [class.prop]/(3.7) 似乎与 [class.prop]/(3.7.3) 矛盾。我错过了什么?

转载 作者:行者123 更新时间:2023-12-03 06:53:59 27 4
gpt4 key购买 nike

A class S is a standard-layout class if it:

[class.prop]/(3.7) :

  • has no element of the set M(S) of types as a base class, where for any type X, M(X) is defined as follows.102[Note: M(X) is the set of the types of all non-base-class subobjectsthat may be at a zero offset in X. — end note]

从上面突出显示的句子我们得出结论,如果 S 是 union ,M(S) 是空的,这仅仅是因为 union 没有基类。对我来说,这与下面的 [class.prop]/(3.7.3) 相矛盾。

[class.prop]/(3.7.3)

  • If X is a union type, the set M(X) is the union of all M(Ui) and the set containing all Ui , where each Ui is the type of the i thnon-static data member of X.

最佳答案

我错了。查看 zygoloid 的答案 here .

关注@GManNickG,我在 GitHub 中复制了 zygoloid 对我的问题的回答:

The wording is correct as-is. Consider:

struct A {};
union U { A a; };
struct B : A { U u; };

Here, B is not standard-layout because M(B) contains A and B has A asa base class. M(B) is defined as U plus M(U), and M(U) is defined asA.

So we need M(U) to be non-empty for M(B) to properly compute "the setof the types of all non-base-class subobjects that may be at a zerooffset in" U, even though U itself can't have base class.

关于c++ - [class.prop]/(3.7) 似乎与 [class.prop]/(3.7.3) 矛盾。我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63973380/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com