I have a class and a given quite complicated method for the sake of which I’ve defined some auxiliary functions, which aren’t however used anywhere else. Now I’m wondering whether I should
- add them to my class – it seems to be what it should be done according to the OOP paradigm
- keep them outside, i.e. separately, only in my implementation file – since filling up my class definition with that sort of semi-redundant methods would make my class definition less readable.
My question is what should I do when C++ style is concerned. I feel that the second solution goes against the OOP principles, though C++ isn’t an object-oriented language but a hybrid one. The functions I mention, if implemented as class methods, would be static.
Put them in an Unnamed namespace inside your source file.
The unnamed namespace allows your functions to be visible within the translation unit, but not outside the translation unit. Your functions still have an external linkage but they are simply invisible to anyone outside the translation unit.