I don't know why, but it still makes me twitch... however since half the programmers out there do that... I'll just have to get use to it at some point.
@naraku VC++2008 Express Edition (I have to use it for compatibility with an SDK)
@Oria My pet peeve is when people define a class with the class keyword instead of the struct keyword, because 99% of the time they only use public inheritance and have the public: keyword right up front.
@Catfish3: I also can't compile anything that prefixes c function names with std:: even if you include the <c****> headers, which the standard mandates should be in the std:: namespace. For example, this won't compile for me:
1 2 3 4 5 6
#include <cstdio>
int main()
{
std::printf("Hello, cstdio!");
}
I was going to write a rant to explain the reasons why I don't like it... but I am getting extremely sleepy so I'll just say it annoys me and I wish people wouldn't do it.
@Oria My pet peeve is when people define a class with the class keyword instead of the struct keyword, because 99% of the time they only use public inheritance and have the public: keyword right up front.
Yeah I would have to agree that if you use a "class", it should be because you intent to use private fields, etc. However I usually use classes most of the time because I believe you should keep your members private.
class my_class {
public:
int hypothetical_public_member;
my_class(int _value);
void do_the_things();
private:
int value;
int some_other_members();
void do_the_first_thing();
void do_the_second_thing();
void do_the_third_thing();
};
I like to put the public interface first so that someone looking at the header file doesn't have to scroll down through the private stuff - which they don't need to know - to find it.
I use struct for very simple classes which only (or mostly) use public members and are POD (or almost-POD). For example, this is a struct I used in a game (so that less code would need to be changed to port the game from SFML to, say, SDL):
I use struct for very simple classes which only (or mostly) use public members[...]
I use class/struct interchangeably--often whichever one saves a line. A lot of developers think it's a big deal or something to define a constructor in a "struct", etc..
I much prefer a switch with a quit case & a default clause to handle bad input, with the whole thing in a bool controlled while loop.
With structs, I like to use them to create types to help achieve function overloading where there is only 1 member variable . For example with geometric classes where there are lots of points & double values. Point objects would still be classes, because they can be used on their own where public access isn't correct. That way I can have public access to the members of the struct, but have the structs as private members of the class. Think of an arc with centre points, start & end points, points on the arc, start & end angles, and various distances. I think it is important to always have the structs as private members in a class object.
With private variables, I like them at the start of the class for 2 reasons: I like to know straight away what member variables are in a class; I don't like seeing the use of private variables, in initialiser lists or otherwise, before the declaration of the variables.
The best part is that without changing the code it will slowly get faster as compilers get better at optimizing abstracted code that uses the standard library :)
I meant that I see this sort of thing from newbies all the time, so my solution caters for them - templates are way too much for a newbies.
Also, this sort of thing is usually for a menu of some kind, or a basic calculator - so a switch inside a while seems perfectly OK IMO. The newbies code is only there to validate the input, I prefer to use the default clause for that. And it is scalable in the switch, rather than trying to get all the options on 1 LOC.