user855 user855 - 1 month ago 9x
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?

Ajay G.


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

camelCase for functions and variables.

PascalCase for classes.


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).