struct
and class
in C++ are nearly identical (as covered for example here).
But why is this so? What did happen when C++ was developed and eventually standardized, that struct
was allowed to define a full OOP class, yet class
keyword was also added? There must be a historical reason for this, but I did not find an answer by searching.
In contrast, for example C# uses these keywords too, but there they have different and distinct meaning. I would say this is quite a valuable feature in that language.
In hindsight, it would have for example made sense to keep C++ struct
be always compatible with similar C struct
in memory layout, and only those class features that are compatible with that would have been supported (so no "virtual" stuff, value always copyable by memcpy
, maybe even some kind of C interoperability for struct
methods). Or something else perhaps; point is, the distinction could have meant something and added to the language, instead of being a (small) source of confusion it is now.
So I am looking for some historical record, quote or story, which would explain this.