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?
Since C++11, you may want to use either snake_case
or camelCase
for function names.
This is because to make a class work as the range-expression in a range-based for-loop, you have to define functions called begin
and end
(case-sensitive) for that class.
Consequently, using e.g. PascalCase
for function names means you have to break the naming consistency in your project if you ever need to make a class work with the range-based for.