Structures versus classes
You are right, the main difference between a structure and a class in C ++ is the default access levels. Without an explicit access modifier, class members are private, and structure members are public. Struct elements can also be made private using an access modifier. Keep in mind that this also applies to inherited classes and structures.
As for the general recommendation: many adhere to the use of structures only for data and classes for everything related to behavior [1]. In other words, structures for POD types (Ordinary old data) [2]. This is a very common practice. This does not mean that you cannot have functionality related to accessing and setting up data members, setting up constructors, destructors, etc. "If more functions are required, the class is more suitable. If in doubt, make it a class." Their guide also recommends structures instead of classes for functors and attributes.
You must bear in mind, in addition to any technical problems or shortcomings, there are other reasons for applying specific practices and standards in a team and on a project basis. As also mentioned in the Google Style Guide, we can add our own semantic meaning to the data structures that we use. As a member of the team, I would like to know if the structures have behavior or not. It would be nice to know, for example, that all structures are just POD types.
The Joint Strike Fighter coding standard defines "The structure should be used to model an object that does not require an invariant." Although "the class should be used to model an object that supports the invariant." And that public and secure data should only be used in structures, not in classes. Their rationale is that the class cannot control access to public members; therefore, all data in the class must be private. The needs of your project should always be considered when deciding on coding standards.
Structure inheritance
When considering inheritance, you should consider what inheritance is, not personal inheritance. You should remember what access levels the new ones obtained from them have, and if it makes sense to inherit your structures. Struct elements can be private; if you inherit this, the derived will not have access to the underlying private members.
struct base { int public_data; private: int private_data; }; struct derived : base { derived() { public_data = 1;
In other words, inheritance can be seen as a logical problem rather than an implementation.
There is nothing technically fundamentally wrong with the inheritance of structures. It can be a benevolent practice, and in some cases it can be useful and make a lot of sense.
Keep in mind that in C ++, structures can be inherited from classes and vice versa.
See this question for more information on vtables: When is a vtable created in C ++?
[1] https://google.imtqy.com/styleguide/cppguide.html#Structs_vs._Classes
[2] http://en.cppreference.com/w/cpp/concept/PODType