The only difference between a class and a structure in C ++ is that of access specifiers .
For classes, the default access specifier is private.
For structures, the default access specifier is public.
This means that if you have a class derived from another class / structure, it will be private inheritance by default & If you have a structure belonging to another class / structure, by default it will be public inheritance.
One problem is that since the default access specifier for a structure is publicly available, they can expose members that may not need to be exposed to class inference. In this sense, all encapsulation has a whole new dimension. Of course, you can change the access specifiers inside the structure that you are going to use as a base, then you can avoid the problem, but it may not be possible, since this can affect how the structure is used from other parts of the program.
EDIT:
Thanks to the comments, I have a fair idea what mistakes you have in mind, errors are not specifically related to the fact that you are leaving the structure, but because you misunderstand the rules of the Inheritance and Access specifications.
Here is an example demo program:
You can check the launch of the same here in Ideone.
You will notice that even if you change the base type from struct FirstStruct to class FirstStruct here , you get the same errors (nothing more).
Invite you to see this answer here to understand the rules for inheritance and access specifications.
source share