user855 user855 - 3 months ago 16
C++ Question

C++ naming: read_input() vs. readInput()

Which naming convention is more preferable in C++? The `underscore' method or the camelCase method?
I have coded in Java for a while and I am used to the camelCase naming conventions.
Which one is more prevalent?

Also, while defining a class, is there any preferred ordering of private/public/protected variables/methods?

Are friends usually put in the end?

What about typedefs, do they come at the top of the class definition?

Thanks,
Ajay G.

Answer

This is all very subjective, but generally for C++ I do:

camelCase for functions and variables.

PascalCase for classes.

public:
protected:
private:

In classes.

Edit: Forgot these 2:

Yes, friend at the end, typedef either at the beginning if they are used in the class, or after if they use the class (for obvious reasons).