In C + +, it is possible to use structkeyword to define classes, and to define classes with class keyword, so what is the difference between the two?
The only difference is that the default access permissions for struct and class are different.
Assuming that we use structkeyword, the members that are defined before the first access specifier are public ; instead, if you are using classkeyword, these members are Private .
I think it's possible to understand thatstructkeyword is a c-style type definition,class is a C + + style type definition, and we know that object-oriented C + + has better encapsulation characteristics, As a result, its members are defined as private by default.
Reference book: "C + + Primer Chinese version (5th edition)"
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
C + + in struct and class differences