Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good naming convention for private member functions in C++?

For members, I use

//.......vv
SomeType m_XXX;
//.......^^

I'd love to use _ as a prefix for member functions, but names starting with _ or __ are reserved and should not be used.

My idea is, that when I have:

SomeClass myObject;
myObject.[XXX]

when the user (of the lib) write the dot (.), to see all functions (one after another) that are only public.

Is there a common naming convention for this?

I know, that I can use pImpl or inheritance, with interface and implementation classes

like image 633
Kiril Kirov Avatar asked Aug 20 '12 10:08

Kiril Kirov


2 Answers

The most common practice is to name member functions without any common prefix or suffix. Personally, I see no benefit in differentiating them, and if your motivation relates to "write the dot (.), to see all functions" then it sounds like you should configure or change your editor, rather than change your programming style to suit it.

like image 176
Tony Delroy Avatar answered Oct 12 '22 08:10

Tony Delroy


A good convention is the trailing underscore, like_this_. Leading underscore is the Python way, however, in C++ all identifiers starting with underscore are reserved for the implementation.

Another option is to always prefix member access with this.

like image 32
Maxim Egorushkin Avatar answered Oct 12 '22 08:10

Maxim Egorushkin