c++ - C 结构是未装箱的,而 C++ 结构是装箱类型?

标签 c++ c struct

正如许多书籍所提到的,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++ 中创建一个未装箱的类型,它也包含实例方法?

最佳答案

在我看来完全是胡说八道。

成员并没有神奇地“位于其他地方”,不涉及指针,并且 header 与它毫无关系。 C++ 编译器甚至不知道 header 的存在!

关于c++ - C 结构是未装箱的,而 C++ 结构是装箱类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9186172/

相关文章:

c# - 在 C++/C# 之间的结构内传递字符串/数组

c++ - 在 C++ 项目中导出 DLL

c - typedef 结构混淆中的指针

c++ - CUDA 内核异常行为,生成随机值

c - 结构中 ‘:’ 标记之前出现错误 : expected ‘,’ , ‘;’、 ‘}’、 ‘__attribute__’ 或 ‘=’

C编程: Reading in Data

c - 将链表写入二进制文件(C)

c++ - 我的 C++ 函数在不应该的时候破坏了变量

c++ - 在所有方向上移动矩阵列/行 C++

c++ - 在 Qt 中压缩一个 .txt 文件