There is something that I constantly encounter while working on C ++ code.
Say I have a method that does X, Y, and then Z. Now I would like to introduce another method that should do X, Y ', Z. If it were a plain old C code, I would then make X functions ( ) and Z () with common code, declaring them static , so that the compiler can now be embedded if necessary, since the code cannot call them from this “module”. A method that will be part of the API will look like
int M(args) { X(foo);
Now, if I do the same in C ++, X () and Z () no longer have access to the class' protected / private members. Switching between .h and .cc files to declare these “helpers” X () and Z () when I start writing code somehow tempts me to just copy / paste the common code instead, so I try to duplicate the class, having something that is closer to the (java) interface in .h - with virtually no member variables, and then have variables, API methods, and “helper” methods in the class block in the .cc file, which inherits from the “interface” .
However, I doubt this is good practice with C ++, so I am curious to know what other people do in this case.
source share