c++functioncoding-stylenaming-conventions

Function names in C++: Capitalize or not?


What's the convention for naming functions in C++?

I come from the Java environment so I usually name something like:

myFunction(...) {
}

I've seen mixed code in C++,

myFunction(....)
MyFunction(....)
Myfunction(....)

What's the correct way?

Also, is it the same for a class method as well as a non-class method?


Solution

  • There isn't a 'correct way'. They're all syntactically correct, though there are some conventions. You could follow the Google style guide, although there are others out there.

    From said guide:

    Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExcitingMethod(), my_exciting_member_variable(), set_my_exciting_member_variable().