加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

当C struct是盒装类型时,C struct是unboxed吗?

发布时间:2020-12-16 10:30:52 所属栏目:百科 来源:网络整理
导读:正如许多书中提到的,与C struct和class的区别在于访问控制描述符.因此,我想知道以下陈述是否正确: struct in C is unboxed: members in the struct are plainly located next to where the struct is allocated. But struct in C++ is a boxed type like cl
正如许多书中提到的,与C struct和class的区别在于访问控制描述符.因此,我想知道以下陈述是否正确:

struct in C is unboxed: members in the struct are plainly located next to where the struct is allocated.
But struct in C++ is a boxed type like class: members/headers are located somewhere else,and where the struct is allocated contains a pointer to the members/headers.

这种理解对吗?

是否可以在C中创建一个包含实例方法的未装箱类型?

解决方法

此讨论中缺少的关键字是“POD”( Plain Old Data structure). (拳击与.NET和可能的Java有关 – 虽然我不记得使用这个词的Java术语)

POD基本上意味着它可以通过’blitting bits'(memcpy,memmov)在内存中移动. C标准规范中有明确的要求.

C结构总是POD(普通旧数据),而C类可以具有与(虚拟)继承相关的“额外魔法”.

看这个:

What are POD types in C++?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读