As many books mentioned, the difference with C++ struct and class is the access control descriptor. Thus I am wondering if the following statement is right:
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.
Is this understanding right?
And is it possible to create a unboxed type in C++, that also contains instance methods?
The missing keyword in this discussion is ‘POD’ (Plain Old Data structure). (Boxing is related to .NET and possibly Java – though I don’t recall Java terminology using the word)
A POD basically means that it can be moved around in memory just by ‘blitting bits’ (memcpy, memmov). There are explicit requirements in the C++ standard specifications.
C structs are always POD (plain old data), whereas C++ classes can have ‘extra magic’ related to (virtual) inheritance.
Look at this:
What are POD types in C++?