开发者

What's the most interesting wrong view people have on the difference between structure and class in C++? [closed]

开发者 https://www.devze.com 2023-01-05 03:00 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying 开发者_JAVA技巧this question so that it can be reopened, visit the help center. Closed 12 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消