c++ source code organization for free functions

c++

Solution

You could put the free functions that deal with a particular class in the class header and implementation file if there are not too many.

Otherwise, come up with a naming convention and put them in a separate header and implementation file (e.g ClassNameFunctions.h/.cpp).

Problem

I want to start to prefer free (non-member) functions over member functions - following this article http://www.drdobbs.com/184401197 I am used to organize my C++ classes in that way, that I have `ClassName.h` for the declaration and a `ClassName.C` for the implementation. ``` ClassName.h : struct ClassName { ClassName(); void setData( unsigned data ); }; ``` and the implementation is then ``` ClassName.C : #include "ClassName.h" ClassName::ClassName() { dosomething(); }; void setData( unsigned data ) { dootherthings(); }; ``` So how do I organize my code when I want have a free function `adjustClassData()` ? I also want to put this function into namespace. Assuming `ClassName` is in `namespace foo`, then I would put the free function into `namespace foo` as well: ``` namespace foo { void adjustClassData( ClassName & inObj ); } ``` I am looking for the aspects of `namespace` and suggestions for file names. I am looking for some best-practices - as there is no C++ rule in the standard prescribing the file organization.

Original source