c – 覆盖超类联合的子类联合ontop

c – 覆盖超类联合的子类联合ontop,第1张

概述我想知道是否可以将成员附加到子类中的C联合. class A { ... union { int a; int b; }; }; class B : public A { ... int c; //<- Can this use the same storage as the union? }; 一个更具体的例子是标记联合的想法,你希望有一个子类为联合 我想知道是否可以将成员附加到子类中的C联合.
class A {     ...    union { int a; int b; }; }; class B : public A {     ...     int c; //<- Can this use the same storage as the union? };

一个更具体的例子是标记联合的想法,你希望有一个子类为联合添加一个类型.

解决方法 你说,

I’m wondering if it’s possible to append members to a C++ union in a subclass.

该语言不允许扩展联合.无法将成员附加到工会.

更糟糕的是,与可以通过创建子类(结构)扩展的类和结构不同,联合不能具有基类.它们也可能不被用作基类.

总结

以上是内存溢出为你收集整理的c – 覆盖超类联合的子类联合ontop全部内容,希望文章能够帮你解决c – 覆盖超类联合的子类联合ontop所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1241247.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存