正如许多书籍所提到的,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/