views:

107

answers:

3

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

+4  A: 

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.

Mark Byers
what about the size of an empty class and an empty struct?
pythonperl
+6  A: 

Classes are from Mars, and structs are from Venus.

Tyler McHenry
+3  A: 

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.

Mark Ransom