What's the most interesting wrong view people have on the difference between structure and class in C++?
Classes are from Mars, and structs are from Venus.
For those who are interested in what the actual difference is, the default access specified for structs is public, and for classes it is private. There is no other difference.
See this related answer.
Member of a class defined with the keyword class are private by default. Members of a class defined with the keywords struct or union are public by default.
In absence of an access-specifier for a base class, public is assumed when the derived class is declared struct and private is assumed when the class is declared class.
I can imagine a lot of people thinking that there will be a performance difference but there is not.
It is very easy to assume that a struct
cannot have methods. This is false; I will sometimes put a constructor on a struct, for example.
精彩评论