I just signed on, but noticed a question posted to the Beginners forum. It was a very, very "beginner" question, and was answered very quickly and clearly with no snark. This is a sign of a good community, and very encouraging to me as I find things to ask about.
Did...did you seriously just write "class [...] { public:" ? DID YOU SERIOUSLY?
Could say the same thing about:
1 2 3
class [...] : public ..., public ..., public ...
{
};
That doesn't mean you should use struct or change the order you write your code in simply to avoid a redundant 7 keystrokes / a line of code.
I only ever use struct for POD or anonymous structures. It makes more sense to have the public members first, it doesn't matter to the implementer but to someone reading the code as a user generally they won't be looking at the private section.
This was one thing I did enjoy about D. While not actually having a very well-endowed standard, they removed the need for redundant keywords. Struct and class mean two different things in D and are treated differently (outside of just semantics and permissions).
Yah it is too bad C++ didn't make that distinction I almost never implement virtual functions (and other features) in a struct and it's obviously impossible to do so in C.
I always use the struct keyword for classes in C++, just because I like proving that it's valid. The only time I use the class keyword is when I am making an example for e.g. a beginner who probably thinks that a struct is for POD and a class is for OOP. Plus struct definitions look prettier and less redundant on average, though that's just my personal opinion.
I would actually like to know, however, why some people put multiple consecutive access specifiers, like why people will put "public:", then some functions, then another "public:", and some more functions. Does this actually do anything? Is it some convention? I'd like to know because it seems odd.
I used to do it because I wanted to split up code and data. I'd put private data at the top, private methods next, then public data and then public methods last.